From 5dd290f2b2aae876a31ebb641521016be512cefa Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 5 May 2017 01:01:29 +0300 Subject: [PATCH] '(mb_)substr(...)' used as index-based access. (cherry picked from commit e89f017) --- library/attach_mod/displaying.php | 2 +- .../attach_mod/includes/functions_attach.php | 40 ++++++++++--------- library/includes/classes/correct.php | 4 +- library/includes/smtp.php | 2 +- library/includes/template.php | 2 +- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/library/attach_mod/displaying.php b/library/attach_mod/displaying.php index 0a010d9f6..6d2b91f44 100644 --- a/library/attach_mod/displaying.php +++ b/library/attach_mod/displaying.php @@ -83,7 +83,7 @@ function init_display_template($template_var, $replacement, $filename = 'viewtop } $complete_filename = $filename; - if (substr($complete_filename, 0, 1) != '/') { + if ($complete_filename[0] != '/') { $complete_filename = $template->root . '/' . $complete_filename; } diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 5f0b371e0..54a71347b 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -49,7 +49,9 @@ function base64_pack($number) if ($number > 4096) { return; - } elseif ($number < $base) { + } + + if ($number < $base) { return $chars[$number]; } @@ -81,7 +83,7 @@ function base64_unpack($string) for ($i = 1; $i <= $length; $i++) { $pos = $length - $i; - $operand = strpos($chars, substr($string, $pos, 1)); + $operand = strpos($chars, $string[$pos]); $exponent = pow($base, $i - 1); $decValue = $operand * $exponent; $number += $decValue; @@ -129,11 +131,13 @@ function auth_unpack($auth_cache) $auth_len = 1; for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) { - $forum_auth = substr($auth_cache, $pos, 1); + $forum_auth = $auth_cache[$pos]; if ($forum_auth == $one_char_encoding) { $auth_len = 1; continue; - } elseif ($forum_auth == $two_char_encoding) { + } + + if ($forum_auth == $two_char_encoding) { $auth_len = 2; $pos--; continue; @@ -162,11 +166,13 @@ function is_forum_authed($auth_cache, $check_forum_id) $auth_len = 1; for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) { - $forum_auth = substr($auth_cache, $pos, 1); + $forum_auth = $auth_cache[$pos]; if ($forum_auth == $one_char_encoding) { $auth_len = 1; continue; - } elseif ($forum_auth == $two_char_encoding) { + } + + if ($forum_auth == $two_char_encoding) { $auth_len = 2; $pos--; continue; @@ -210,9 +216,9 @@ function attachment_exists($filename) if (!@file_exists(@amod_realpath($upload_dir . '/' . $filename))) { return false; - } else { - return true; } + + return true; } /** @@ -226,9 +232,9 @@ function thumbnail_exists($filename) if (!@file_exists(@amod_realpath($upload_dir . '/' . THUMB_DIR . '/t_' . $filename))) { return false; - } else { - return true; } + + return true; } /** @@ -412,9 +418,9 @@ function get_extension($filename) $extension = strtolower(trim($extension)); if (is_array($extension)) { return ''; - } else { - return $extension; } + + return $extension; } /** @@ -495,11 +501,9 @@ function _set_var(&$result, $var, $type, $multibyte = false) */ function get_var($var_name, $default, $multibyte = false) { - if ( - !isset($_REQUEST[$var_name]) || + if (!isset($_REQUEST[$var_name]) || (is_array($_REQUEST[$var_name]) && !is_array($default)) || - (is_array($default) && !is_array($_REQUEST[$var_name])) - ) { + (is_array($default) && !is_array($_REQUEST[$var_name]))) { return (is_array($default)) ? [] : $default; } @@ -544,9 +548,9 @@ function attach_mod_sql_escape($text) { if (function_exists('mysqli_real_escape_string')) { return DB()->escape_string($text); - } else { - return str_replace("'", "''", str_replace('\\', '\\\\', $text)); } + + return str_replace("'", "''", str_replace('\\', '\\\\', $text)); } /** diff --git a/library/includes/classes/correct.php b/library/includes/classes/correct.php index 14ceb602c..cd0c42150 100644 --- a/library/includes/classes/correct.php +++ b/library/includes/classes/correct.php @@ -2956,7 +2956,7 @@ class Text_LangCorrect */ #0a. английский --> русский: - if (substr($word, 1, 1) === '.' #оптимизация + if ($word[1] === '.' #оптимизация && preg_match('/^ ( ' . $this->en_similar_uc . '\. #первый инициал (?:' . $this->en_similar_uc . '\.)? #второй инициал (необязательно) ) #1 инициалы @@ -2973,7 +2973,7 @@ class Text_LangCorrect } #0b. русский --> английский: - if (substr($word, 2, 1) === '.' #оптимизация + if ($word[2] === '.' #оптимизация && preg_match('/^ ( ' . $this->ru_similar_uc . '\. #первый инициал (?:' . $this->ru_similar_uc . '\.)? #второй инициал (необязательно) ) #1 инициалы diff --git a/library/includes/smtp.php b/library/includes/smtp.php index 672fbbb5e..c138bca1e 100644 --- a/library/includes/smtp.php +++ b/library/includes/smtp.php @@ -32,7 +32,7 @@ define('SMTP_INCLUDED', 1); function server_parse($socket, $response, $line = __LINE__) { $server_response = ''; - while (substr($server_response, 3, 1) != ' ') { + while ($server_response[3] != ' ') { if (!($server_response = fgets($socket, 256))) { bb_die('Could not get mail server response codes'); } diff --git a/library/includes/template.php b/library/includes/template.php index 45395a134..eae67b601 100644 --- a/library/includes/template.php +++ b/library/includes/template.php @@ -173,7 +173,7 @@ class template $filename = $this->replace[$filename]; } // Check if it's an absolute or relative path. - if ((substr($filename, 0, 1) !== '/') && (substr($filename, 1, 1) !== ':')) { + if (($filename[0] !== '/') && ($filename[1] !== ':')) { return $this->root . '/' . $filename; } else { return $filename;