[2/4] Check query return value in search_results_page()

Message ID 20170418065254.8200-2-lfleischer@archlinux.org
State Accepted, archived
Headers show
Series
  • [1/4] Check query return value in pkgbase_user_notify()
Related show

Commit Message

Lukas Fleischer April 18, 2017, 6:52 a.m. UTC
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(-)

Patch

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");