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