[aur-dev] [PATCH 1/4] Check query return value in pkgbase_user_notify()
Instead of unconditionally calling fetch on the return value of query(), error out early if the value evaluates to false. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/pkgbasefuncs.inc.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index cd4b271..57933e8 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -852,12 +852,11 @@ function pkgbase_user_notify($uid, $base_id) { $q.= " AND PackageBaseID = " . $dbh->quote($base_id); $result = $dbh->query($q); - if ($result->fetch(PDO::FETCH_NUM)) { - return true; - } - else { + if (!$result) { return false; } + + return ($result->fetch(PDO::FETCH_NUM) > 0); } /** -- 2.12.2
Instead of unconditionally calling fetch on the return value of query(), error out early if the value evaluates to false. Also, make sure that the results array is always initialized, even if the result set is empty. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/acctfuncs.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index 3c8f9ed..22b3ca8 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -495,8 +495,11 @@ function search_results_page($O=0,$SB="",$U="",$T="", $result = $dbh->query($q); - while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $userinfo[] = $row; + $userinfo = array(); + if ($result) { + while ($row = $result->fetch(PDO::FETCH_ASSOC)) { + $userinfo[] = $row; + } } include("account_search_results.php"); -- 2.12.2
Instead of unconditionally calling fetch on the return value of query(), error out early if the value evaluates to false. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/cachefuncs.inc.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/lib/cachefuncs.inc.php b/web/lib/cachefuncs.inc.php index d558be4..faeae5a 100644 --- a/web/lib/cachefuncs.inc.php +++ b/web/lib/cachefuncs.inc.php @@ -73,6 +73,9 @@ function db_cache_value($dbq, $key, $ttl=600) { $value = get_cache_value($key, $status); if (!$status) { $result = $dbh->query($dbq); + if (!$result) { + return false; + } $row = $result->fetch(PDO::FETCH_NUM); $value = $row[0]; set_cache_value($key, $value, $ttl); -- 2.12.2
Make sure that the get_extended_fields() invocation succeeded before merging regular and extended fields in process_query(). Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/aurjson.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index e07522d..9eeaafd 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -313,7 +313,10 @@ class AurJSON { } if ($this->version >= 2 && ($type == 'info' || $type == 'multiinfo')) { - $row = array_merge($row, $this->get_extended_fields($row['ID'], $row['PackageBaseID'])); + $extfields = $this->get_extended_fields($row['ID'], $row['PackageBaseID']); + if ($extfields) { + $row = array_merge($row, $extfields); + } } if ($this->version < 3) { -- 2.12.2
participants (1)
-
Lukas Fleischer