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