Skip to content

Commit

Permalink
Some more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdarwood007 committed Dec 30, 2023
1 parent 0d4c902 commit 218ccef
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
3 changes: 2 additions & 1 deletion Sources/Actions/Admin/SearchEngines.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ public function logs(): void

Utils::$context['spider_logs']['rows'][$k]['data']['viewing']['class'] = $new_url['class'];
} else {
Utils::$context['spider_logs']['rows'][$k]['data']['viewing']['value'] = $new_url;
// @TODO: Indirect modification of overloaded element of SMF\ItemList has no effect in
@Utils::$context['spider_logs']['rows'][$k]['data']['viewing']['value'] = $new_url;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public static function getTree(): void

foreach (self::queryData($selects, $params, $joins, $where, $order) as $row) {
if (!isset(self::$loaded[$row['id_cat']])) {
self::init($row['id_cat'], [
self::init((int) $row['id_cat'], [
'name' => $row['cat_name'],
'description' => $row['cat_desc'],
'order' => $row['cat_order'],
Expand All @@ -717,7 +717,7 @@ public static function getTree(): void
$row['deny_member_groups'] = explode(',', $row['deny_member_groups']);
$row['prev_board'] = $prevBoard;

Board::init($row['id_board'], $row);
Board::init((int) $row['id_board'], $row);

$prevBoard = $row['id_board'];
$last_board_order = $row['board_order'];
Expand Down
16 changes: 10 additions & 6 deletions Sources/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,25 @@ public static function ip2range(string $addr): array
* Convert a range of IP addresses into a single string.
* It's practically the reverse function of ip2range().
*
* @param string $low The low end of the range.
* @param string $high The high end of the range.
* @param string|IP $low The low end of the range.
* @param string|IP $high The high end of the range.
* @return string A string indicating the range.
*/
public static function range2ip(string $low, string $high): string
public static function range2ip(string|IP $low, string|IP $high): string
{
$low = new IP($low);
$high = new IP($high);
if (!$low instanceof IP) {
$low = new IP($low);
}
if (!$high instanceof IP) {
$high = new IP($high);
}

if ($low == '255.255.255.255') {
return 'unknown';
}

if ($low == $high) {
return $low;
return (string) $low;
}

return $low . '-' . $high;
Expand Down
16 changes: 11 additions & 5 deletions Sources/ItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ItemList implements \ArrayAccess
*
* The page index for navigating this list.
*/
public string $page_index;
public PageIndex $page_index;

/**
* @var array
Expand Down Expand Up @@ -351,7 +351,7 @@ protected function setStartAndItemsPerPage(): void

$params = $this->options['get_count']['params'] ?? [];

$this->total_num_items = call_user_func_array($call, array_values($params));
$this->total_num_items = (int) call_user_func_array($call, array_values($params));
}

// Default the start to the beginning...sounds logical.
Expand All @@ -368,7 +368,13 @@ protected function buildPageIndex(): void
return;
}

$this->page_index = new PageIndex($this->options['base_href'] . (empty($this->sort) ? '' : ';' . $this->options['request_vars']['sort'] . '=' . $this->sort['id'] . ($this->sort['desc'] ? ';' . $this->options['request_vars']['desc'] : '')) . ($this->start_var_name != 'start' ? ';' . $this->start_var_name . '=%1$d' : ''), $this->start, $this->total_num_items, $this->items_per_page, $this->start_var_name != 'start');
$this->page_index = new PageIndex(
$this->options['base_href'] . (empty($this->sort) ? '' : ';' . $this->options['request_vars']['sort'] . '=' . $this->sort['id'] . ($this->sort['desc'] ? ';' . $this->options['request_vars']['desc'] : '')) . ($this->start_var_name != 'start' ? ';' . $this->start_var_name . '=%1$d' : ''),
$this->start,
$this->total_num_items,
$this->items_per_page,
$this->start_var_name != 'start'
);
}

/**
Expand Down Expand Up @@ -408,14 +414,14 @@ protected function buildRows(): void
}
// Take the value from the database and make it HTML safe.
elseif (isset($column['data']['db_htmlsafe'])) {
$cur_data['value'] = Utils::htmlspecialchars($list_item[$column['data']['db_htmlsafe']]);
$cur_data['value'] = Utils::htmlspecialchars((string) $list_item[$column['data']['db_htmlsafe']]);
}
// Using sprintf is probably the most readable way of injecting data.
elseif (isset($column['data']['sprintf'])) {
$params = [];

foreach ($column['data']['sprintf']['params'] as $sprintf_param => $htmlsafe) {
$params[] = $htmlsafe ? Utils::htmlspecialchars($list_item[$sprintf_param]) : $list_item[$sprintf_param];
$params[] = $htmlsafe ? Utils::htmlspecialchars((string) $list_item[$sprintf_param]) : $list_item[$sprintf_param];
}

$cur_data['value'] = vsprintf($column['data']['sprintf']['format'], $params);
Expand Down
2 changes: 1 addition & 1 deletion Sources/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public static function sendSmtp(array $mail_to_array, string $subject, string $m
}

// Try to connect to the SMTP server... if it doesn't exist, only wait three seconds.
if (!$socket = fsockopen(Config::$modSettings['smtp_host'], empty(Config::$modSettings['smtp_port']) ? 25 : Config::$modSettings['smtp_port'], $errno, $errstr, 3)) {
if (!$socket = fsockopen(Config::$modSettings['smtp_host'], empty(Config::$modSettings['smtp_port']) ? 25 : (int) Config::$modSettings['smtp_port'], $errno, $errstr, 3)) {
// Maybe we can still save this? The port might be wrong.
if (substr(Config::$modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty(Config::$modSettings['smtp_port']) || Config::$modSettings['smtp_port'] == 25)) {
// ssl:hostname can cause fsocketopen to fail with a lookup failure, ensure it exists for this test.
Expand Down
6 changes: 3 additions & 3 deletions Sources/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ public function runScheduledTasks(array $tasks): void
while ($row = Db::$db->fetch_assoc($request)) {
// What kind of task are we handling?
if (!empty($row['callable'])) {
$task_details = $this->getScheduledTaskDetails($row['id_task'], $row['callable'], true);
$task_details = $this->getScheduledTaskDetails((int) $row['id_task'], $row['callable'], true);
} elseif (!empty($row['task'])) {
$task_details = $this->getScheduledTaskDetails($row['id_task'], $row['task']);
$task_details = $this->getScheduledTaskDetails((int) $row['id_task'], $row['task']);
} else {
continue;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ public static function calculateNextTrigger(string|array $tasks = [], bool $forc
);

while ($row = Db::$db->fetch_assoc($request)) {
$next_time = self::getNextScheduledTime($row['time_regularity'], $row['time_unit'], $row['time_offset']);
$next_time = self::getNextScheduledTime((int) $row['time_regularity'], $row['time_unit'], (int) $row['time_offset']);

// Only bother moving the task if it's out of place or we're forcing it!
if ($force_update || $next_time < $row['next_time'] || $row['next_time'] < time()) {
Expand Down
42 changes: 21 additions & 21 deletions Sources/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4686,20 +4686,20 @@ protected function setProperties(): void
$this->is_mod = in_array(3, $this->groups) || !empty($profile['is_mod']);
$this->is_activated = (int) ($profile['is_activated'] ?? !$this->is_guest);
$this->is_banned = $this->is_activated >= 10;
$this->is_online = (bool) $profile['is_online'] ?? $is_me;
$this->is_online = (bool) ($profile['is_online'] ?? $is_me);

// User activity and history.
$this->show_online = (bool) $profile['show_online'] ?? false;
$this->show_online = (bool) ($profile['show_online'] ?? false);
$this->url = $profile['url'] ?? '';
$this->last_login = (int) $profile['last_login'] ?? 0;
$this->id_msg_last_visit = (int) $profile['id_msg_last_visit'] ?? 0;
$this->total_time_logged_in = (int) $profile['total_time_logged_in'] ?? 0;
$this->date_registered = (int) $profile['date_registered'] ?? 0;
$this->ip = $is_me ? $_SERVER['REMOTE_ADDR'] : ((string) $profile['member_ip'] ?? '');
$this->ip2 = $is_me ? $_SERVER['BAN_CHECK_IP'] : ((string) $profile['member_ip2'] ?? '');
$this->last_login = (int) ($profile['last_login'] ?? 0);
$this->id_msg_last_visit = (int) ($profile['id_msg_last_visit'] ?? 0);
$this->total_time_logged_in = (int) ($profile['total_time_logged_in'] ?? 0);
$this->date_registered = (int) ($profile['date_registered'] ?? 0);
$this->ip = (string) ($is_me ? $_SERVER['REMOTE_ADDR'] : $profile['member_ip'] ?? '');
$this->ip2 = (string) ($is_me ? $_SERVER['BAN_CHECK_IP'] : $profile['member_ip2'] ?? '');

// Additional profile info.
$this->posts = (int) $profile['posts'] ?? 0;
$this->posts = (int) ($profile['posts'] ?? 0);
$this->title = $profile['usertitle'] ?? '';
$this->signature = $profile['signature'] ?? '';
$this->personal_text = $profile['personal_text'] ?? '';
Expand All @@ -4708,27 +4708,27 @@ protected function setProperties(): void
$this->website['title'] = $profile['website_title'] ?? '';

// Presentation preferences.
$this->theme = (int) $profile['id_theme'] ?? 0;
$this->options = (array) $profile['options'] ?? [];
$this->theme = (int) ($profile['id_theme'] ?? 0);
$this->options = (array) ($profile['options'] ?? []);
$this->smiley_set = $profile['smiley_set'] ?? '';

// Localization.
$this->setLanguage();
$this->time_format = empty($profile['time_format']) ? Config::$modSettings['time_format'] : $profile['time_format'];
$this->timezone = $profile['timezone'] ?? Config::$modSettings['default_timezone'];
$this->time_offset = (int) $profile['time_offset'] ?? 0;
$this->time_offset = (int) ($profile['time_offset'] ?? 0);

// Buddies and personal messages.
$this->buddies = !empty(Config::$modSettings['enable_buddylist']) && !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : [];
$this->ignoreusers = !empty($profile['pm_ignore_list']) ? explode(',', $profile['pm_ignore_list']) : [];
$this->pm_receive_from = (int) $profile['pm_receive_from'] ?? 0;
$this->pm_prefs = (int) $profile['pm_prefs'] ?? 0;
$this->messages = (int) $profile['instant_messages'] ?? 0;
$this->unread_messages = (int) $profile['unread_messages'] ?? 0;
$this->new_pm = (int) $profile['new_pm'] ?? 0;
$this->pm_receive_from = (int) ($profile['pm_receive_from'] ?? 0);
$this->pm_prefs = (int) ($profile['pm_prefs'] ?? 0);
$this->messages = (int) ($profile['instant_messages'] ?? 0);
$this->unread_messages = (int) ($profile['unread_messages'] ?? 0);
$this->new_pm = (int) ($profile['new_pm'] ?? 0);

// What does the user want to see or know about?
$this->alerts = (int) $profile['alerts'] ?? 0;
$this->alerts = (int) ($profile['alerts'] ?? 0);
$this->ignoreboards = !empty($profile['ignore_boards']) && !empty(Config::$modSettings['allow_ignore_boards']) ? explode(',', $profile['ignore_boards']) : [];

// Extended membergroup info.
Expand Down Expand Up @@ -4760,7 +4760,7 @@ protected function setProperties(): void

// Info about stuff related to permissions.
// Note that we set $this->permissions elsewhere.
$this->warning = (int) $profile['warning'] ?? 0;
$this->warning = (int) ($profile['warning'] ?? 0);
$this->can_manage_boards = !empty($this->is_admin) || (!empty(Config::$modSettings['board_manager_groups']) && !empty($this->groups) && count(array_intersect($this->groups, explode(',', Config::$modSettings['board_manager_groups']))) > 0);

foreach (self::buildQueryBoard($this->id) as $key => $value) {
Expand Down Expand Up @@ -5247,10 +5247,10 @@ protected function setPossiblyRobot(): void
self::logSpider();
}

$this->possibly_robot = !empty($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0;
$this->possibly_robot = !empty($_SESSION['id_robot']);
}
} elseif (!empty(Config::$modSettings['spider_mode'])) {
$this->possibly_robot = $_SESSION['id_robot'] ?? 0;
$this->possibly_robot = !empty($_SESSION['id_robot']);
}
// If we haven't turned on proper spider hunts then have a guess!
else {
Expand Down

0 comments on commit 218ccef

Please # to comment.