Re: [aur-dev][PATCH 0/2] php warning fixes

2020-02-12 Thread Lukas Fleischer
On Wed, 12 Feb 2020 at 21:16:36, Eli Schwartz wrote:
> I had this sitting around since December and forgot to send it in,
> offered FWIW. It's slightly different in implementation and has more
> wordy commit messages.

Thanks. I will discard the other patch I submitted earlier (Verify that
returned rows exist before extracting columns) and apply these two
instead.


[aur-dev][PATCH 1/2] fix php 7.4 warnings

2020-02-12 Thread Eli Schwartz
If a db query returned NULL instead of an array, then accessing $row[0]
now throws a warning. The undocumented behavior of evaluating to NULL
is maintained, and we want to return NULL anyway, so add a check for the
value and fall back on the default function return type.

Signed-off-by: Eli Schwartz 
---
 web/lib/aur.inc.php  | 28 +---
 web/lib/pkgfuncs.inc.php |  4 +++-
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index e9530fc0..dbcc23a4 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -197,7 +197,9 @@ function username_from_id($id) {
}
 
$row = $result->fetch(PDO::FETCH_NUM);
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
@@ -222,7 +224,9 @@ function username_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
 
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
@@ -339,7 +343,9 @@ function email_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
 
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
@@ -365,7 +371,9 @@ function account_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
 
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
@@ -390,7 +398,9 @@ function uid_from_sid($sid="") {
}
$row = $result->fetch(PDO::FETCH_NUM);
 
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
@@ -512,7 +522,9 @@ function uid_from_username($username) {
}
 
$row = $result->fetch(PDO::FETCH_NUM);
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
@@ -546,7 +558,9 @@ function uid_from_email($email) {
}
 
$row = $result->fetch(PDO::FETCH_NUM);
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index a4cd17ac..8c915711 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -147,7 +147,9 @@ function pkg_from_name($name="") {
return;
}
$row = $result->fetch(PDO::FETCH_NUM);
-   return $row[0];
+   if ($row) {
+   return $row[0];
+   }
 }
 
 /**
-- 
2.25.0


[aur-dev][PATCH 2/2] fix more php 7.4 warnings

2020-02-12 Thread Eli Schwartz
The try_login() function documents it returns an array containing an
'error' key, and our only caller *only* consults the 'error' key. Then
the function returns null instead of an array, if the login succeeded!

I question why we bother returning the new SID if we never use it,
surely we could either return the error or return default null. But, for
now, I'm just going to fix it to return what it's actually supposed to,
without changing the API.

Signed-off-by: Eli Schwartz 
---
 web/lib/acctfuncs.inc.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php
index 443fb4b1..d238c0e0 100644
--- a/web/lib/acctfuncs.inc.php
+++ b/web/lib/acctfuncs.inc.php
@@ -659,6 +659,7 @@ function try_login() {
}
header("Location: " . get_uri($referer));
$login_error = "";
+   return array('SID' => $new_sid, 'error' => null);
 }
 
 /**
-- 
2.25.0


[aur-dev][PATCH 0/2] php warning fixes

2020-02-12 Thread Eli Schwartz
I had this sitting around since December and forgot to send it in,
offered FWIW. It's slightly different in implementation and has more
wordy commit messages.

Eli Schwartz (2):
  fix php 7.4 warnings
  fix more php 7.4 warnings

 web/lib/acctfuncs.inc.php |  1 +
 web/lib/aur.inc.php   | 28 +---
 web/lib/pkgfuncs.inc.php  |  4 +++-
 3 files changed, 25 insertions(+), 8 deletions(-)

-- 
2.25.0


[PATCH v2] Verify that returned rows exist before extracting columns

2020-02-12 Thread Lukas Fleischer
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 
---
 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


[PATCH] Verify that return rows exist before extracting columns

2020-02-12 Thread Lukas Fleischer
Signed-off-by: Lukas Fleischer 
---
 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