[3/4] Check query return value in db_cache_value()

Message ID 20170418065254.8200-3-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.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
---
 web/lib/cachefuncs.inc.php | 3 +++
 1 file changed, 3 insertions(+)

Patch

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