| @@ 454-498 (lines=45) @@ | ||
| 451 | } |
|
| 452 | ||
| 453 | // First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over. |
|
| 454 | if (empty($modSettings['disableQueryCheck'])) |
|
| 455 | { |
|
| 456 | $clean = ''; |
|
| 457 | $old_pos = 0; |
|
| 458 | $pos = -1; |
|
| 459 | while (true) |
|
| 460 | { |
|
| 461 | $pos = strpos($db_string, '\'', $pos + 1); |
|
| 462 | if ($pos === false) |
|
| 463 | break; |
|
| 464 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
|
| 465 | ||
| 466 | while (true) |
|
| 467 | { |
|
| 468 | $pos1 = strpos($db_string, '\'', $pos + 1); |
|
| 469 | $pos2 = strpos($db_string, '\\', $pos + 1); |
|
| 470 | if ($pos1 === false) |
|
| 471 | break; |
|
| 472 | elseif ($pos2 === false || $pos2 > $pos1) |
|
| 473 | { |
|
| 474 | $pos = $pos1; |
|
| 475 | break; |
|
| 476 | } |
|
| 477 | ||
| 478 | $pos = $pos2 + 1; |
|
| 479 | } |
|
| 480 | $clean .= ' %s '; |
|
| 481 | ||
| 482 | $old_pos = $pos + 1; |
|
| 483 | } |
|
| 484 | $clean .= substr($db_string, $old_pos); |
|
| 485 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
|
| 486 | ||
| 487 | // Comments? We don't use comments in our queries, we leave 'em outside! |
|
| 488 | if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 489 | $fail = true; |
|
| 490 | // Trying to change passwords, slow us down, or something? |
|
| 491 | elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 492 | $fail = true; |
|
| 493 | elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 494 | $fail = true; |
|
| 495 | ||
| 496 | if (!empty($fail) && function_exists('log_error')) |
|
| 497 | smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 498 | } |
|
| 499 | ||
| 500 | if (empty($db_unbuffered)) |
|
| 501 | $ret = @mysqli_query($connection, $db_string); |
|
| @@ 421-465 (lines=45) @@ | ||
| 418 | } |
|
| 419 | ||
| 420 | // First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over. |
|
| 421 | if (empty($modSettings['disableQueryCheck'])) |
|
| 422 | { |
|
| 423 | $clean = ''; |
|
| 424 | $old_pos = 0; |
|
| 425 | $pos = -1; |
|
| 426 | while (true) |
|
| 427 | { |
|
| 428 | $pos = strpos($db_string, '\'', $pos + 1); |
|
| 429 | if ($pos === false) |
|
| 430 | break; |
|
| 431 | $clean .= substr($db_string, $old_pos, $pos - $old_pos); |
|
| 432 | ||
| 433 | while (true) |
|
| 434 | { |
|
| 435 | $pos1 = strpos($db_string, '\'', $pos + 1); |
|
| 436 | $pos2 = strpos($db_string, '\\', $pos + 1); |
|
| 437 | if ($pos1 === false) |
|
| 438 | break; |
|
| 439 | elseif ($pos2 === false || $pos2 > $pos1) |
|
| 440 | { |
|
| 441 | $pos = $pos1; |
|
| 442 | break; |
|
| 443 | } |
|
| 444 | ||
| 445 | $pos = $pos2 + 1; |
|
| 446 | } |
|
| 447 | $clean .= ' %s '; |
|
| 448 | ||
| 449 | $old_pos = $pos + 1; |
|
| 450 | } |
|
| 451 | $clean .= substr($db_string, $old_pos); |
|
| 452 | $clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean))); |
|
| 453 | ||
| 454 | // Comments? We don't use comments in our queries, we leave 'em outside! |
|
| 455 | if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false) |
|
| 456 | $fail = true; |
|
| 457 | // Trying to change passwords, slow us down, or something? |
|
| 458 | elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0) |
|
| 459 | $fail = true; |
|
| 460 | elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0) |
|
| 461 | $fail = true; |
|
| 462 | ||
| 463 | if (!empty($fail) && function_exists('log_error')) |
|
| 464 | smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__); |
|
| 465 | } |
|
| 466 | ||
| 467 | // Set optimize stuff |
|
| 468 | if (isset($query_opt[$identifier])) |
|