Verify that return rows exist before extracting columns

Message ID 20200212152320.13763-1-lfleischer@archlinux.org
State New
Headers show
Series
  • Verify that return rows exist before extracting columns
Related show

Commit Message

Lukas Fleischer Feb. 12, 2020, 3:23 p.m. UTC
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(+)

Patch

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];
 }