From a5825b78ede06c89e4503d499b9c672722349caa Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Fri, 15 Jan 2021 00:02:13 +0100 Subject: [PATCH 01/10] =?UTF-8?q?Fix=20db=5Fresult()=20emitting=20?= =?UTF-8?q?=E2=80=9CNotice:=20Trying=20to=20access=20array=20offset=20on?= =?UTF-8?q?=20value=20of=20type=20null=E2=80=9D=20when=20called=20repeated?= =?UTF-8?q?ly=20on=20the=20same=20result=20set.=20(PHP7.4;=20Warning=20in?= =?UTF-8?q?=20PHP8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/database.mysql.inc | 6 +++++- includes/database.mysqli.inc | 6 +++++- includes/database.pgsql.inc | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 1b2a2382b96..bd729f4f8dd 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -192,7 +192,11 @@ function db_result($result) { // The mysql_fetch_row function has an optional second parameter $row // but that can't be used for compatibility with Oracle, DB2, etc. $array = mysql_fetch_row($result); - return $array[0]; + // This function was never meant to be used multiple times on the same + // result set (resulting in $array being FALSE). But the above spec is not + // absolutely clear about that, so various code is doing it, and PHP < 7.4 + // didn't emit any PHP Notices. So now, we effectively support it... + return isset($array[0]) ? $array[0] : FALSE; } return FALSE; } diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc index b373730eabc..b08c12f44f4 100644 --- a/includes/database.mysqli.inc +++ b/includes/database.mysqli.inc @@ -192,7 +192,11 @@ function db_result($result) { // The mysqli_fetch_row function has an optional second parameter $row // but that can't be used for compatibility with Oracle, DB2, etc. $array = mysqli_fetch_row($result); - return $array[0]; + // This function was never meant to be used multiple times on the same + // result set (resulting in $array being NULL). But the above spec is not + // absolutely clear about that, so various code is doing it, and PHP < 7.4 + // didn't emit any PHP Notices. So now, we effectively support it... + return isset($array[0]) ? $array[0] : FALSE; } return FALSE; } diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index da7c4f970a4..7aff4d13167 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -206,7 +206,11 @@ function db_fetch_array($result) { function db_result($result) { if ($result && pg_num_rows($result) > 0) { $array = pg_fetch_row($result); - return $array[0]; + // This function was never meant to be used multiple times on the same + // result set (resulting in $array being FALSE). But the above spec is not + // absolutely clear about that, so various code is doing it, and PHP < 7.4 + // didn't emit any PHP Notices. So now, we effectively support it... + return isset($array[0]) ? $array[0] : FALSE; } return FALSE; } From 7ccc85d881e356b94d3eafacdffc01202f123aa8 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Thu, 14 Jan 2021 23:55:21 +0100 Subject: [PATCH 02/10] Fix "Trying to access array offset on value of type null" in user edit screen (PHP7.4) --- modules/user/user.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/user/user.module b/modules/user/user.module index 5ff9a35a361..b5f272f1d18 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1533,7 +1533,7 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) { if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) { $form['account']['name'] = array('#type' => 'textfield', '#title' => t('Username'), - '#default_value' => $edit['name'], + '#default_value' => isset($edit['name']) ? $edit['name'] : NULL, '#maxlength' => USERNAME_MAX_LENGTH, '#description' => t('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), '#required' => TRUE, @@ -1541,7 +1541,7 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) { } $form['account']['mail'] = array('#type' => 'textfield', '#title' => t('E-mail address'), - '#default_value' => $edit['mail'], + '#default_value' => isset($edit['mail']) ? $edit['mail'] : NULL, '#maxlength' => EMAIL_MAX_LENGTH, '#description' => t('A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), '#required' => TRUE, From cba4d376adc59cf11a89648216db6e6af2526cbb Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Thu, 14 Jan 2021 23:55:52 +0100 Subject: [PATCH 03/10] Fix "Trying to access array offset on value of type null" in forum_get_topics() (PHP7.4) --- modules/forum/forum.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/forum/forum.module b/modules/forum/forum.module index d656f109012..58e7e05cf75 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -582,7 +582,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { ); $order = _forum_get_topic_order($sortby); - for ($i = 0; $i < count($forum_topic_list_header); $i++) { + for ($i = 1; $i < count($forum_topic_list_header); $i++) { if ($forum_topic_list_header[$i]['field'] == $order['field']) { $forum_topic_list_header[$i]['sort'] = $order['sort']; } From b7dde84109603b527f0f7b3af8f47e97b77bdff4 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Fri, 15 Jan 2021 00:02:58 +0100 Subject: [PATCH 04/10] Fix notice for array offset on value of type null in _drupal_build_css_path() (#3084953 backport; PHP7.4) --- includes/common.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/common.inc b/includes/common.inc index 045dd9b3032..8953007cf2d 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2050,7 +2050,7 @@ function _drupal_build_css_path($matches, $base = NULL) { } // Prefix with base and remove '../' segments where possible. - $path = $_base . $matches[1]; + $path = $_base . (isset($matches[1]) ? $matches[1]: ''); $last = ''; while ($path != $last) { $last = $path; From a14c3608225f8e003bdaf0ea0755cb3539627127 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Fri, 15 Jan 2021 00:06:30 +0100 Subject: [PATCH 05/10] =?UTF-8?q?Different=20implementation=20of=20#308495?= =?UTF-8?q?3=20backport,=20which=20documents=20what=E2=80=99s=20going=20on?= =?UTF-8?q?=20rather=20than=20just=20adding=20an=20isset()=20somewhere.=20?= =?UTF-8?q?(Functionally=20equivalent,=20though.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/common.inc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/common.inc b/includes/common.inc index 8953007cf2d..bd82515ecf0 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2041,6 +2041,19 @@ function drupal_build_css_cache($types, $filename) { * Helper function for drupal_build_css_cache(). * * This function will prefix all paths within a CSS file. + * + * @param array|null $matches + * A 'matches' array as would be populated by e.g. preg_match() - meaning + * $matches[0] has text that matched the full pattern and $matches[1] has + * text that matched the first captured parenthesized subpattern. We assume + * $matchesIf NULL, + * then don't return anything useful; only set the base path for future calls. + * @param string|null $base + * The base path to use for prefixing. + * + * @return string|null + * A CSS path (prefixed, and surrounded with "url()" - or NULL if the first + * parameter was NULL. */ function _drupal_build_css_path($matches, $base = NULL) { static $_base; @@ -2048,9 +2061,12 @@ function _drupal_build_css_path($matches, $base = NULL) { if (isset($base)) { $_base = $base; } + if (!isset($matches[1])) { + return NULL; + } // Prefix with base and remove '../' segments where possible. - $path = $_base . (isset($matches[1]) ? $matches[1]: ''); + $path = $_base . $matches[1]; $last = ''; while ($path != $last) { $last = $path; From 463a85824172e2649089f9131e2395b08befe4d3 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 20 Jan 2021 21:49:49 +0100 Subject: [PATCH 06/10] Fix notices if menu_get_item() returns FALSE (#3085088 backport) --- includes/menu.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/menu.inc b/includes/menu.inc index 4788855415d..442b62e5372 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1539,7 +1539,7 @@ function menu_set_active_trail($new_trail = NULL) { $item = menu_get_item(); // Check whether the current item is a local task (displayed as a tab). - if ($item['tab_parent']) { + if (!empty($item['tab_parent'])) { // The title of a local task is used for the tab, never the page title. // Thus, replace it with the item corresponding to the root path to get // the relevant href and title. For example, the menu item corresponding @@ -1580,7 +1580,7 @@ function menu_set_active_trail($new_trail = NULL) { // Make sure the current page is in the trail (needed for the page title), // but exclude tabs and the front page. $last = count($trail) - 1; - if ($trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) { + if ($item && $trail[$last]['href'] != $item['href'] && !(bool)($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) { $trail[] = $item; } } From adc5f2abff4d78e31049429bcecf2fe0b4f138a7 Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 20 Jan 2021 21:48:37 +0100 Subject: [PATCH 07/10] Fix Undefined Index notices in block_admin_configure() --- modules/block/block.admin.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc index 3fd8280a9c7..3beafefeb70 100644 --- a/modules/block/block.admin.inc +++ b/modules/block/block.admin.inc @@ -160,7 +160,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { '#title' => t('Block title'), '#maxlength' => 64, '#description' => $module == 'block' ? t('The title of the block as shown to the user.') : t('Override the default title for the block. Use <none> to display no title, or leave blank to use the default block title.'), - '#default_value' => $edit['title'], + '#default_value' => $edit ? $edit['title'] : NULL, '#weight' => -18, ); @@ -193,7 +193,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { t('Hide this block by default but let individual users show it.') ), '#description' => t('Allow individual users to customize the visibility of this block in their account settings.'), - '#default_value' => $edit['custom'], + '#default_value' => $edit ? $edit['custom'] : NULL, ); // Role-based visibility settings @@ -227,7 +227,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { ); $access = user_access('use PHP for block visibility'); - if ($edit['visibility'] == 2 && !$access) { + if ($edit && $edit['visibility'] == 2 && !$access) { $form['page_vis_settings'] = array(); $form['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2); $form['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $edit['pages']); @@ -244,12 +244,12 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) { '#type' => 'radios', '#title' => t('Show block on specific pages'), '#options' => $options, - '#default_value' => $edit['visibility'], + '#default_value' => $edit ? $edit['visibility'] : NULL, ); $form['page_vis_settings']['pages'] = array( '#type' => 'textarea', '#title' => t('Pages'), - '#default_value' => $edit['pages'], + '#default_value' => $edit ? $edit['pages'] : NULL, '#description' => $description, ); } From e90c52957053a24cb626899f4a0c74147f16d16a Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Wed, 20 Jan 2021 21:59:34 +0100 Subject: [PATCH 08/10] Fix "Deprecated: Required parameter ... follows optional parameter" in PHP8 --- modules/book/book.module | 2 +- modules/comment/comment.admin.inc | 2 +- modules/contact/contact.admin.inc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/book/book.module b/modules/book/book.module index 37d8c06f135..31c451821ad 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -860,7 +860,7 @@ function _book_toc_recurse($tree, $indent, &$toc, $exclude, $depth_limit) { * @return * An array of mlid, title pairs for use as options for selecting a book page. */ -function book_toc($bid, $exclude = array(), $depth_limit) { +function book_toc($bid, $exclude, $depth_limit) { $tree = menu_tree_all_data(book_menu_name($bid)); $toc = array(); diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc index 62120490fcd..38c1cfa85a4 100644 --- a/modules/comment/comment.admin.inc +++ b/modules/comment/comment.admin.inc @@ -33,7 +33,7 @@ function comment_admin($type = 'new') { * @see comment_admin_overview_submit() * @see theme_comment_admin_overview() */ -function comment_admin_overview($type = 'new', $arg) { +function comment_admin_overview($type, $arg) { // build an 'Update options' form $form['options'] = array( '#type' => 'fieldset', '#title' => t('Update options'), diff --git a/modules/contact/contact.admin.inc b/modules/contact/contact.admin.inc index e7a5defd08b..bd71f4f45e1 100644 --- a/modules/contact/contact.admin.inc +++ b/modules/contact/contact.admin.inc @@ -22,7 +22,7 @@ function contact_admin_categories() { /** * Category edit page. */ -function contact_admin_edit($form_state = array(), $op, $contact = NULL) { +function contact_admin_edit($form_state, $op, $contact = NULL) { if (empty($contact) || $op == 'add') { $contact = array( From 60fdc671e91d807802e5814c504c53e3c2f9599b Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Thu, 21 Jan 2021 23:11:32 +0100 Subject: [PATCH 09/10] Fix Notice: Undefined index: key in format_xml_elements() (#939810) --- includes/common.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/common.inc b/includes/common.inc index bd82515ecf0..5fe47dc42cc 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1179,7 +1179,7 @@ function format_xml_elements($array) { $output = ''; foreach ($array as $key => $value) { if (is_numeric($key)) { - if ($value['key']) { + if (!empty($value['key'])) { $output .= ' <'. $value['key']; if (isset($value['attributes']) && is_array($value['attributes'])) { $output .= drupal_attributes($value['attributes']); From c1da4fbf94a10b8088de9566652e2fc2536253ac Mon Sep 17 00:00:00 2001 From: Roderik Muit Date: Thu, 21 Jan 2021 23:27:43 +0100 Subject: [PATCH 10/10] Fix Notice: Undefined index: type in dblog_build_filter_query() (#1004820) --- modules/dblog/dblog.admin.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/dblog/dblog.admin.inc b/modules/dblog/dblog.admin.inc index 853a2ce14c8..3448bd00026 100644 --- a/modules/dblog/dblog.admin.inc +++ b/modules/dblog/dblog.admin.inc @@ -191,8 +191,10 @@ function dblog_build_filter_query() { foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) { $filter_where = array(); foreach ($filter as $value) { - $filter_where[] = $filters[$key]['where']; - $args[] = $value; + if (isset($filters[$key]['where'])) { + $filter_where[] = $filters[$key]['where']; + $args[] = $value; + } } if (!empty($filter_where)) { $where[] = '('. implode(' OR ', $filter_where) .')';