| @@ 396-442 (lines=47) @@ | ||
| 393 | } |
|
| 394 | ||
| 395 | // First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over. |
|
| 396 | if (empty($modSettings['disableQueryCheck'])) |
|
| 397 | { |
|
| 398 | $clean = ''; |
|
| 399 | $old_pos = 0; |
|
| 400 | $pos = -1; |
|
| 401 | // Remove the string escape for better runtime |
|
| 402 | $db_string_1 = str_replace('\'\'','',$db_string); |
|
| 403 | while (true) |
|
| 404 | { |
|
| 405 | $pos = strpos($db_string_1, '\'', $pos + 1); |
|
| 406 | if ($pos === false) |
|
| 407 | break; |
|
| 408 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
|
| 409 | ||
| 410 | while (true) |
|
| 411 | { |
|
| 412 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
|
| 413 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
|
| 414 | if ($pos1 === false) |
|
| 415 | break; |
|
| 416 | elseif ($pos2 === false || $pos2 > $pos1) |
|
| 417 | { |
|
| 418 | $pos = $pos1; |
|
| 419 | break; |
|
| 420 | } |
|
| 421 | ||
| 422 | $pos = $pos2 + 1; |
|
| 423 | } |
|
| 424 | $clean .= ' %s '; |
|
| 425 | ||
| 426 | $old_pos = $pos + 1; |
|
| 427 | } |
|
| 428 | $clean .= substr($db_string_1, $old_pos); |
|
| 429 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
|
| 430 | ||
| 431 | // Comments? We don't use comments in our queries, we leave 'em outside! |
|
| 432 | if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 433 | $fail = true; |
|
| 434 | // Trying to change passwords, slow us down, or something? |
|
| 435 | elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 436 | $fail = true; |
|
| 437 | elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 438 | $fail = true; |
|
| 439 | ||
| 440 | if (!empty($fail) && function_exists('log_error')) |
|
| 441 | smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 442 | } |
|
| 443 | ||
| 444 | // Set optimize stuff |
|
| 445 | if (isset($query_opt[$identifier])) |
|
| @@ 401-447 (lines=47) @@ | ||
| 398 | } |
|
| 399 | ||
| 400 | // First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over. |
|
| 401 | if (empty($modSettings['disableQueryCheck'])) |
|
| 402 | { |
|
| 403 | $clean = ''; |
|
| 404 | $old_pos = 0; |
|
| 405 | $pos = -1; |
|
| 406 | // Remove the string escape for better runtime |
|
| 407 | $db_string_1 = str_replace('\\\'','',$db_string); |
|
| 408 | while (true) |
|
| 409 | { |
|
| 410 | $pos = strpos($db_string_1, '\'', $pos + 1); |
|
| 411 | if ($pos === false) |
|
| 412 | break; |
|
| 413 | $clean .= substr($db_string_1, $old_pos, $pos - $old_pos); |
|
| 414 | ||
| 415 | while (true) |
|
| 416 | { |
|
| 417 | $pos1 = strpos($db_string_1, '\'', $pos + 1); |
|
| 418 | $pos2 = strpos($db_string_1, '\\', $pos + 1); |
|
| 419 | if ($pos1 === false) |
|
| 420 | break; |
|
| 421 | elseif ($pos2 === false || $pos2 > $pos1) |
|
| 422 | { |
|
| 423 | $pos = $pos1; |
|
| 424 | break; |
|
| 425 | } |
|
| 426 | ||
| 427 | $pos = $pos2 + 1; |
|
| 428 | } |
|
| 429 | $clean .= ' %s '; |
|
| 430 | ||
| 431 | $old_pos = $pos + 1; |
|
| 432 | } |
|
| 433 | $clean .= substr($db_string_1, $old_pos); |
|
| 434 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
|
| 435 | ||
| 436 | // Comments? We don't use comments in our queries, we leave 'em outside! |
|
| 437 | if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 438 | $fail = true; |
|
| 439 | // Trying to change passwords, slow us down, or something? |
|
| 440 | elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 441 | $fail = true; |
|
| 442 | elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 443 | $fail = true; |
|
| 444 | ||
| 445 | if (!empty($fail) && function_exists('log_error')) |
|
| 446 | smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 447 | } |
|
| 448 | ||
| 449 | // Debugging. |
|
| 450 | if (isset($db_show_debug) && $db_show_debug === true) |
|