[PATCH] Verify that return rows exist before extracting columns
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/aur.inc.php | 21 +++++++++++++++++++++ web/lib/pkgfuncs.inc.php | 3 +++ 2 files changed, 24 insertions(+) diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index e9530fc..2507df6 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -197,6 +197,9 @@ function username_from_id($id) { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -222,6 +225,9 @@ function username_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -339,6 +345,9 @@ function email_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -365,6 +374,9 @@ function account_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -390,6 +402,9 @@ function uid_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -512,6 +527,9 @@ function uid_from_username($username) { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -546,6 +564,9 @@ function uid_from_email($email) { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index a4cd17a..b30bfa9 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -147,6 +147,9 @@ function pkg_from_name($name="") { return; } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } -- 2.25.0
Fix PHP notices such as "Trying to access array offset on value of type bool" or "Trying to access array offset on value of type null". Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/html/login.php | 4 +++- web/lib/aur.inc.php | 21 +++++++++++++++++++++ web/lib/pkgfuncs.inc.php | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/web/html/login.php b/web/html/login.php index 0145441..5308147 100644 --- a/web/html/login.php +++ b/web/html/login.php @@ -6,7 +6,9 @@ include_once("aur.inc.php"); $disable_http_login = config_get_bool('options', 'disable_http_login'); if (!$disable_http_login || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'])) { $login = try_login(); - $login_error = $login['error']; + if ($login) { + $login_error = $login['error']; + } } html_header('AUR ' . __("Login")); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index e9530fc..2507df6 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -197,6 +197,9 @@ function username_from_id($id) { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -222,6 +225,9 @@ function username_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -339,6 +345,9 @@ function email_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -365,6 +374,9 @@ function account_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -390,6 +402,9 @@ function uid_from_sid($sid="") { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -512,6 +527,9 @@ function uid_from_username($username) { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } @@ -546,6 +564,9 @@ function uid_from_email($email) { } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index a4cd17a..b30bfa9 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -147,6 +147,9 @@ function pkg_from_name($name="") { return; } $row = $result->fetch(PDO::FETCH_NUM); + if (!$row) { + return null; + } return $row[0]; } -- 2.25.0
participants (1)
-
Lukas Fleischer