Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static code analyzer cherry picked from #228 #229

Merged
merged 32 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
609696d
Fix require file.
diolektor May 7, 2017
3f05049
Fix sql. Remove excess "group by".
diolektor May 7, 2017
2aa166e
Fix check version php.
diolektor May 7, 2017
7e29eb9
Binary-unsafe 'fopen(...)' usage
Exileum May 4, 2017
f8d84bc
'safe_mode' is a deprecated option since PHP 5.3.0 (removed in PHP 5.…
Exileum May 4, 2017
b9330f6
Unit of measure 'px' is redundant.
Exileum May 4, 2017
7599090
If-return-return could be simplified.
Exileum May 4, 2017
dcd19e5
One-time use variables.
Exileum May 4, 2017
fc8d71d
Strings normalization.
Exileum May 4, 2017
02a06e6
Ternary operator could be simplified.
Exileum May 4, 2017
6eed2e8
'unset(...)' calls could be merged.
Exileum May 4, 2017
6abd9ba
Alias functions usage.
Exileum May 4, 2017
3fbd958
Deprecated constructor style.
Exileum May 4, 2017
ba2e294
__DIR__ constant can be used.
Exileum May 4, 2017
13e3cf6
Elvis operator can be used.
Exileum May 4, 2017
64df3c5
'null === ...' can be used.
Exileum May 4, 2017
21c8e7d
Type casting can be used.
Exileum May 4, 2017
8d2c7b2
'array_push(...)' misused.
Exileum May 4, 2017
4dcb113
'file(...)' misused.
Exileum May 4, 2017
5dd290f
'(mb_)substr(...)' used as index-based access.
Exileum May 4, 2017
8e5338e
'str(i)str(...)' could be replaced with 'str(i)pos(...)'.
Exileum May 4, 2017
05442c4
'stristr(...)/stripos(...)/strripos(...)' could be replaced with 'str…
Exileum May 4, 2017
99c79f2
Insecure 'uniqid(...)' usage (Insufficient Entropy Vulnerability).
Exileum May 4, 2017
5d6039d
Parameter could be declared as array.
Exileum May 4, 2017
3351953
Class property initialization flaws.
Exileum May 4, 2017
a1ca9a0
Callable name case mismatched in a call.
Exileum May 4, 2017
748476b
Prefixed increment/decrement equivalent.
Exileum May 4, 2017
1daec3c
Short syntax for applied operation.
Exileum May 4, 2017
4e021d0
Static methods invocation via '->'.
Exileum May 4, 2017
32ca1d6
Unnecessary semicolon.
Exileum May 4, 2017
56540c8
Change for with count.
diolektor May 7, 2017
8f7ef8a
Unnecessary semicolon.
Exileum May 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions admin/admin_attach_cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@

// Are we called from Username ?
if ($user_based) {
$sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = " . intval($uid);
$sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = " . (int)$uid;

if (!($result = DB()->sql_query($sql))) {
bb_die('Error getting username');
Expand All @@ -343,7 +343,7 @@
DB()->sql_freeresult($result);
$username = $row['username'];

$s_hidden = '<input type="hidden" name="u_id" value="' . intval($uid) . '" />';
$s_hidden = '<input type="hidden" name="u_id" value="' . (int)$uid . '" />';

$template->assign_block_vars('switch_user_based', array());

Expand All @@ -354,7 +354,7 @@

$sql = "SELECT attach_id
FROM " . BB_ATTACHMENTS . "
WHERE user_id_1 = " . intval($uid) . "
WHERE user_id_1 = " . (int)$uid . "
GROUP BY attach_id";

if (!($result = DB()->sql_query($sql))) {
Expand All @@ -374,7 +374,7 @@
$attach_id = array();

for ($j = 0; $j < $num_attach_ids; $j++) {
$attach_id[] = intval($attach_ids[$j]['attach_id']);
$attach_id[] = (int)$attach_ids[$j]['attach_id'];
}

$sql = "SELECT a.*
Expand All @@ -394,13 +394,13 @@
$attachments = search_attachments($order_by, $total_rows);
}

if (sizeof($attachments) > 0) {
if (count($attachments) > 0) {
for ($i = 0, $iMax = count($attachments); $i < $iMax; $i++) {
$delete_box = '<input type="checkbox" name="delete_id_list[]" value="' . intval($attachments[$i]['attach_id']) . '" />';
$delete_box = '<input type="checkbox" name="delete_id_list[]" value="' . (int)$attachments[$i]['attach_id'] . '" />';

for ($j = 0, $iMax = count($delete_id_list); $j < $iMax; $j++) {
if ($delete_id_list[$j] == $attachments[$i]['attach_id']) {
$delete_box = '<input type="checkbox" name="delete_id_list[]" value="' . intval($attachments[$i]['attach_id']) . '" checked="checked" />';
$delete_box = '<input type="checkbox" name="delete_id_list[]" value="' . (int)$attachments[$i]['attach_id'] . '" checked="checked" />';
break;
}
}
Expand All @@ -413,7 +413,7 @@

$sql = "SELECT *
FROM " . BB_ATTACHMENTS . "
WHERE attach_id = " . intval($attachments[$i]['attach_id']);
WHERE attach_id = " . (int)$attachments[$i]['attach_id'];

if (!($result = DB()->sql_query($sql))) {
bb_die('Could not query attachments #3');
Expand All @@ -427,7 +427,7 @@
if ($ids[$j]['post_id'] != 0) {
$sql = "SELECT t.topic_title
FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
WHERE p.post_id = " . intval($ids[$j]['post_id']) . " AND p.topic_id = t.topic_id
WHERE p.post_id = " . (int)$ids[$j]['post_id'] . " AND p.topic_id = t.topic_id
GROUP BY t.topic_id, t.topic_title";

if (!($result = DB()->sql_query($sql))) {
Expand All @@ -452,7 +452,7 @@

$post_titles = implode('<br />', $post_titles);

$hidden_field = '<input type="hidden" name="attach_id_list[]" value="' . intval($attachments[$i]['attach_id']) . '" />';
$hidden_field = '<input type="hidden" name="attach_id_list[]" value="' . (int)$attachments[$i]['attach_id'] . '" />';

$template->assign_block_vars('attachrow', array(
'ROW_NUMBER' => $i + (@$_GET['start'] + 1),
Expand Down
16 changes: 8 additions & 8 deletions admin/admin_attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$module['ATTACHMENTS']['QUOTA_LIMITS'] = $filename . '?mode=quota';
return;
}
require('./pagestart.php');
require __DIR__ . '/pagestart.php';

$error = false;

Expand Down Expand Up @@ -220,7 +220,7 @@
}

if (!$error) {
if (!($fp = @fopen($upload_dir . '/0_000000.000', 'w'))) {
if (!($fp = @fopen($upload_dir . '/0_000000.000', 'wb'))) {
$error = true;
$error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $attach_config['upload_dir']) . '<br />';
} else {
Expand Down Expand Up @@ -248,8 +248,8 @@
'S_FILESIZE' => $select_size_mode,
'S_FILESIZE_QUOTA' => $select_quota_size_mode,
'S_FILESIZE_PM' => $select_pm_size_mode,
'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', intval(trim($new_attach['default_upload_quota']))),
'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', intval(trim($new_attach['default_pm_quota']))),
'S_DEFAULT_UPLOAD_LIMIT' => default_quota_limit_select('default_upload_quota', (int)trim($new_attach['default_upload_quota'])),
'S_DEFAULT_PM_LIMIT' => default_quota_limit_select('default_pm_quota', (int)trim($new_attach['default_pm_quota'])),

'UPLOAD_DIR' => $new_attach['upload_dir'],
'ATTACHMENT_IMG_PATH' => $new_attach['upload_img'],
Expand Down Expand Up @@ -288,7 +288,7 @@
$row = DB()->sql_fetchrowset($result);
DB()->sql_freeresult($result);

for ($i = 0; $i < sizeof($row); $i++) {
for ($i = 0, $iMax = count($row); $i < $iMax; $i++) {
if ($row[$i]['cat_id'] == IMAGE_CAT) {
$s_assigned_group_images[] = $row[$i]['group_name'];
}
Expand Down Expand Up @@ -375,7 +375,7 @@
}

if (!$error) {
if (!($fp = @fopen($upload_dir . '/0_000000.000', 'w'))) {
if (!($fp = @fopen($upload_dir . '/0_000000.000', 'wb'))) {
$error = true;
$error_msg = sprintf($lang['DIRECTORY_NOT_WRITEABLE'], $upload_dir) . '<br />';
} else {
Expand All @@ -399,7 +399,7 @@

$allowed_list = array();

for ($i = 0; $i < sizeof($quota_change_list); $i++) {
for ($i = 0, $iMax = count($quota_change_list); $i < $iMax; $i++) {
$filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]);

$sql = 'UPDATE ' . BB_QUOTA_LIMITS . "
Expand Down Expand Up @@ -504,7 +504,7 @@
$rows = DB()->sql_fetchrowset($result);
DB()->sql_freeresult($result);

for ($i = 0; $i < sizeof($rows); $i++) {
for ($i = 0, $iMax = count($rows); $i < $iMax; $i++) {
$size_format = ($rows[$i]['quota_limit'] >= 1048576) ? 'mb' : (($rows[$i]['quota_limit'] >= 1024) ? 'kb' : 'b');

if ($rows[$i]['quota_limit'] >= 1048576) {
Expand Down
4 changes: 2 additions & 2 deletions admin/admin_disallow.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

bb_die($message);
} elseif (isset($_POST['delete_name'])) {
$disallowed_id = (isset($_POST['disallowed_id'])) ? intval($_POST['disallowed_id']) : intval($_GET['disallowed_id']);
$disallowed_id = (isset($_POST['disallowed_id'])) ? (int)$_POST['disallowed_id'] : (int)$_GET['disallowed_id'];

$sql = "DELETE FROM " . BB_DISALLOW . " WHERE disallow_id = $disallowed_id";
$result = DB()->sql_query($sql);
Expand Down Expand Up @@ -87,7 +87,7 @@
if (count($disallowed) <= 0) {
$disallow_select .= '<option value="">' . $lang['NO_DISALLOWED'] . '</option>';
} else {
for ($i = 0; $i < count($disallowed); $i++) {
for ($i = 0, $iMax = count($disallowed); $i < $iMax; $i++) {
$disallow_select .= '<option value="' . $disallowed[$i]['disallow_id'] . '">' . $disallowed[$i]['disallow_username'] . '</option>';
}
}
Expand Down
37 changes: 19 additions & 18 deletions admin/admin_extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
$module['ATTACHMENTS']['EXTENSION_GROUP_MANAGE'] = $filename . '?mode=groups';
return;
}
require('./pagestart.php');

require __DIR__ . '/pagestart.php';

function update_attach_extensions()
{
Expand Down Expand Up @@ -83,9 +84,9 @@ function update_attach_extensions()
// Generate correct Change List
$extensions = array();

for ($i = 0; $i < sizeof($extension_change_list); $i++) {
for ($i = 0, $iMax = count($extension_change_list); $i < $iMax; $i++) {
$extensions['_' . $extension_change_list[$i]]['comment'] = $extension_explain_list[$i];
$extensions['_' . $extension_change_list[$i]]['group_id'] = intval($group_select_list[$i]);
$extensions['_' . $extension_change_list[$i]]['group_id'] = (int)$group_select_list[$i];
}

$sql = 'SELECT * FROM ' . BB_EXTENSIONS . ' ORDER BY ext_id';
Expand All @@ -98,8 +99,8 @@ function update_attach_extensions()
DB()->sql_freeresult($result);

if ($num_rows > 0) {
for ($i = 0; $i < sizeof($extension_row); $i++) {
if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || intval($extension_row[$i]['group_id']) != intval($extensions['_' . $extension_row[$i]['ext_id']]['group_id'])) {
for ($i = 0, $iMax = count($extension_row); $i < $iMax; $i++) {
if ($extension_row[$i]['comment'] != $extensions['_' . $extension_row[$i]['ext_id']]['comment'] || (int)$extension_row[$i]['group_id'] != (int)$extensions['_' . $extension_row[$i]['ext_id']]['group_id']) {
$sql_ary = array(
'comment' => (string)$extensions['_' . $extension_row[$i]['ext_id']]['comment'],
'group_id' => (int)$extensions['_' . $extension_row[$i]['ext_id']]['group_id']
Expand Down Expand Up @@ -250,15 +251,15 @@ function update_attach_extensions()

$allowed_list = array();

for ($i = 0; $i < sizeof($group_allowed_list); $i++) {
for ($j = 0; $j < sizeof($group_change_list); $j++) {
for ($i = 0, $iMax = count($group_allowed_list); $i < $iMax; $i++) {
for ($j = 0, $jMax = count($group_change_list); $j < $iMax; $j++) {
if ($group_allowed_list[$i] == $group_change_list[$j]) {
$allowed_list[$j] = 1;
}
}
}

for ($i = 0; $i < sizeof($group_change_list); $i++) {
for ($i = 0, $iMax = count($group_change_list); $i < $iMax; $i++) {
$allowed = (isset($allowed_list[$i])) ? 1 : 0;

$filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]);
Expand Down Expand Up @@ -471,7 +472,7 @@ function update_attach_extensions()
$add_forums_list = get_var('entries', array(0));
$add_all_forums = false;

for ($i = 0; $i < sizeof($add_forums_list); $i++) {
for ($i = 0, $iMax = count($add_forums_list); $i < $iMax; $i++) {
if ($add_forums_list[$i] == 0) {
$add_all_forums = true;
}
Expand All @@ -489,7 +490,7 @@ function update_attach_extensions()
if (!$add_all_forums) {
$sql = 'SELECT forum_permissions
FROM ' . BB_EXTENSION_GROUPS . '
WHERE group_id = ' . intval($group) . '
WHERE group_id = ' . (int)$group . '
LIMIT 1';

if (!($result = DB()->sql_query($sql))) {
Expand All @@ -506,7 +507,7 @@ function update_attach_extensions()
}

// Generate array for Auth_Pack, do not add doubled forums
for ($i = 0; $i < sizeof($add_forums_list); $i++) {
for ($i = 0, $iMax = count($add_forums_list); $i < $iMax; $i++) {
if (!in_array($add_forums_list[$i], $auth_p)) {
$auth_p[] = $add_forums_list[$i];
}
Expand All @@ -529,7 +530,7 @@ function update_attach_extensions()
// Get the current Forums
$sql = 'SELECT forum_permissions
FROM ' . BB_EXTENSION_GROUPS . '
WHERE group_id = ' . intval($group) . '
WHERE group_id = ' . (int)$group . '
LIMIT 1';

if (!($result = DB()->sql_query($sql))) {
Expand All @@ -543,13 +544,13 @@ function update_attach_extensions()
$auth_p = array();

// Generate array for Auth_Pack, delete the chosen ones
for ($i = 0; $i < sizeof($auth_p2); $i++) {
for ($i = 0, $iMax = count($auth_p2); $i < $iMax; $i++) {
if (!in_array($auth_p2[$i], $delete_forums_list)) {
$auth_p[] = $auth_p2[$i];
}
}

$auth_bitstream = (sizeof($auth_p) > 0) ? auth_pack($auth_p) : '';
$auth_bitstream = (count($auth_p) > 0) ? auth_pack($auth_p) : '';

$sql = 'UPDATE ' . BB_EXTENSION_GROUPS . " SET forum_permissions = '" . attach_mod_sql_escape($auth_bitstream) . "' WHERE group_id = " . (int)$group;

Expand All @@ -562,7 +563,7 @@ function update_attach_extensions()
if ($e_mode == 'perm' && $group) {
$sql = 'SELECT group_name, forum_permissions
FROM ' . BB_EXTENSION_GROUPS . '
WHERE group_id = ' . intval($group) . '
WHERE group_id = ' . (int)$group . '
LIMIT 1';

if (!($result = DB()->sql_query($sql))) {
Expand Down Expand Up @@ -596,7 +597,7 @@ function update_attach_extensions()
}
}

for ($i = 0; $i < sizeof($forum_perm); $i++) {
for ($i = 0, $iMax = count($forum_perm); $i < $iMax; $i++) {
$template->assign_block_vars('allow_option_values', array(
'VALUE' => $forum_perm[$i]['forum_id'],
'OPTION' => htmlCHR($forum_perm[$i]['forum_name']))
Expand All @@ -618,7 +619,7 @@ function update_attach_extensions()
}

while ($row = DB()->sql_fetchrow($result)) {
$forum_option_values[intval($row['forum_id'])] = $row['forum_name'];
$forum_option_values[(int)$row['forum_id']] = $row['forum_name'];
}
DB()->sql_freeresult($result);

Expand Down Expand Up @@ -675,7 +676,7 @@ function update_attach_extensions()
$message .= ($message == '') ? $forum_name : '<br />' . $forum_name;
}

if (sizeof($empty_perm_forums) > 0) {
if (count($empty_perm_forums) > 0) {
$template->assign_vars(array('ERROR_MESSAGE' => $lang['NOTE_ADMIN_EMPTY_GROUP_PERMISSIONS'] . $message));
}
}
Expand Down
7 changes: 4 additions & 3 deletions admin/admin_forum_prune.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
$module['FORUMS']['PRUNE'] = basename(__FILE__);
return;
}
require('./pagestart.php');

require __DIR__ . '/pagestart.php';

$all_forums = -1;
$pruned_total = 0;
Expand All @@ -37,12 +38,12 @@
if (!$var =& $_REQUEST['f'] or !$f_selected = get_id_ary($var)) {
bb_die('Forum not selected');
}
if (!$var =& $_REQUEST['prunedays'] or !$prunedays = abs(intval($var))) {
if (!$var =& $_REQUEST['prunedays'] or !$prunedays = abs((int)$var)) {
bb_die($lang['NOT_DAYS']);
}

$prunetime = TIMENOW - 86400 * $prunedays;
$forum_csv = in_array($all_forums, $f_selected) ? $all_forums : join(',', $f_selected);
$forum_csv = in_array($all_forums, $f_selected) ? $all_forums : implode(',', $f_selected);

$where_sql = ($forum_csv != $all_forums) ? "WHERE forum_id IN($forum_csv)" : '';

Expand Down
Loading