[aur-dev][PATCH 0/2] php warning fixes
I had this sitting around since December and forgot to send it in, offered FWIW. It's slightly different in implementation and has more wordy commit messages. Eli Schwartz (2): fix php 7.4 warnings fix more php 7.4 warnings web/lib/acctfuncs.inc.php | 1 + web/lib/aur.inc.php | 28 +++++++++++++++++++++------- web/lib/pkgfuncs.inc.php | 4 +++- 3 files changed, 25 insertions(+), 8 deletions(-) -- 2.25.0
If a db query returned NULL instead of an array, then accessing $row[0] now throws a warning. The undocumented behavior of evaluating to NULL is maintained, and we want to return NULL anyway, so add a check for the value and fall back on the default function return type. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- web/lib/aur.inc.php | 28 +++++++++++++++++++++------- web/lib/pkgfuncs.inc.php | 4 +++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index e9530fc0..dbcc23a4 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -197,7 +197,9 @@ function username_from_id($id) { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** @@ -222,7 +224,9 @@ function username_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** @@ -339,7 +343,9 @@ function email_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** @@ -365,7 +371,9 @@ function account_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** @@ -390,7 +398,9 @@ function uid_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** @@ -512,7 +522,9 @@ function uid_from_username($username) { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** @@ -546,7 +558,9 @@ function uid_from_email($email) { } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index a4cd17ac..8c915711 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -147,7 +147,9 @@ function pkg_from_name($name="") { return; } $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; + if ($row) { + return $row[0]; + } } /** -- 2.25.0
The try_login() function documents it returns an array containing an 'error' key, and our only caller *only* consults the 'error' key. Then the function returns null instead of an array, if the login succeeded! I question why we bother returning the new SID if we never use it, surely we could either return the error or return default null. But, for now, I'm just going to fix it to return what it's actually supposed to, without changing the API. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- web/lib/acctfuncs.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 443fb4b1..d238c0e0 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -659,6 +659,7 @@ function try_login() { } header("Location: " . get_uri($referer)); $login_error = ""; + return array('SID' => $new_sid, 'error' => null); } /** -- 2.25.0
On Wed, 12 Feb 2020 at 21:16:36, Eli Schwartz wrote:
I had this sitting around since December and forgot to send it in, offered FWIW. It's slightly different in implementation and has more wordy commit messages.
Thanks. I will discard the other patch I submitted earlier (Verify that returned rows exist before extracting columns) and apply these two instead.
participants (2)
-
Eli Schwartz
-
Lukas Fleischer