From 74817ee23827a1591bf97bfc4e6631321e89b490 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 25 Jan 2016 14:05:15 +0545 Subject: Enhance error output when package file not found I had a system that had upgraded but the Notes package had not managed to (re)install. In that situation the Notes item is on the Status menu but there is no notes.xml or other notes code on the the system. When I go to Status->Notes I get: Warning: substr_compare(): The start position cannot exceed initial string length in /usr/local/www/pkg.php ... The warning is because realpath() returns false in this case and cannot be used is a parameter to substr_compare(). Handle this case, and make the error message more informative. --- src/usr/local/www/pkg.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/usr/local/www/pkg.php b/src/usr/local/www/pkg.php index 005495f..c8b09e0 100755 --- a/src/usr/local/www/pkg.php +++ b/src/usr/local/www/pkg.php @@ -77,10 +77,22 @@ if ($xml == "") { } else { $pkg_xml_prefix = "/usr/local/pkg/"; $pkg_full_path = "{$pkg_xml_prefix}/{$xml}"; - if (substr_compare(realpath($pkg_full_path), $pkg_xml_prefix, 0, strlen($pkg_xml_prefix))) { - print_info_box(gettext("ERROR: Invalid path specified.")); + $pkg_realpath = realpath($pkg_full_path); + if (empty($pkg_realpath)) { + $path_error = sprintf(gettext("ERROR: Package path %s not found."), htmlspecialchars($pkg_full_path)); + } else { + if (substr_compare($pkg_realpath, $pkg_xml_prefix, 0, strlen($pkg_xml_prefix))) { + $path_error = sprintf(gettext("ERROR: Invalid path %s specified."), htmlspecialchars($pkg_full_path)); + } + } + + if (!empty($path_error)) { + include("head.inc"); + print_info_box($path_error . "
" . gettext("Try reinstalling the package.")); + include("foot.inc"); die; } + if (file_exists($pkg_full_path)) { $pkg = parse_xml_config_pkg($pkg_full_path, "packagegui"); } else { -- cgit v1.1 From ae2915a4e9a3e351d849d0b3074981ea726a6449 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 25 Jan 2016 21:03:00 +0545 Subject: pkg.php consolidate else-if statement --- src/usr/local/www/pkg.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/usr/local/www/pkg.php b/src/usr/local/www/pkg.php index c8b09e0..ac085b4 100755 --- a/src/usr/local/www/pkg.php +++ b/src/usr/local/www/pkg.php @@ -80,10 +80,8 @@ if ($xml == "") { $pkg_realpath = realpath($pkg_full_path); if (empty($pkg_realpath)) { $path_error = sprintf(gettext("ERROR: Package path %s not found."), htmlspecialchars($pkg_full_path)); - } else { - if (substr_compare($pkg_realpath, $pkg_xml_prefix, 0, strlen($pkg_xml_prefix))) { - $path_error = sprintf(gettext("ERROR: Invalid path %s specified."), htmlspecialchars($pkg_full_path)); - } + } else if (substr_compare($pkg_realpath, $pkg_xml_prefix, 0, strlen($pkg_xml_prefix))) { + $path_error = sprintf(gettext("ERROR: Invalid path %s specified."), htmlspecialchars($pkg_full_path)); } if (!empty($path_error)) { -- cgit v1.1