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