Code Duplication    Length = 45-45 lines in 2 locations

Sources/Subs-Db-postgresql.php 1 location

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

Sources/Subs-Db-mysql.php 1 location

@@ 460-504 (lines=45) @@
457
	}
458
459
	// First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over.
460
	if (empty($modSettings['disableQueryCheck']))
461
	{
462
		$clean = '';
463
		$old_pos = 0;
464
		$pos = -1;
465
		while (true)
466
		{
467
			$pos = strpos($db_string, '\'', $pos + 1);
468
			if ($pos === false)
469
				break;
470
			$clean .= substr($db_string, $old_pos, $pos - $old_pos);
471
472
			while (true)
473
			{
474
				$pos1 = strpos($db_string, '\'', $pos + 1);
475
				$pos2 = strpos($db_string, '\\', $pos + 1);
476
				if ($pos1 === false)
477
					break;
478
				elseif ($pos2 === false || $pos2 > $pos1)
479
				{
480
					$pos = $pos1;
481
					break;
482
				}
483
484
				$pos = $pos2 + 1;
485
			}
486
			$clean .= ' %s ';
487
488
			$old_pos = $pos + 1;
489
		}
490
		$clean .= substr($db_string, $old_pos);
491
		$clean = trim(strtolower(preg_replace($allowed_comments_from, $allowed_comments_to, $clean)));
492
493
		// Comments?  We don't use comments in our queries, we leave 'em outside!
494
		if (strpos($clean, '/*') > 2 || strpos($clean, '--') !== false || strpos($clean, ';') !== false)
495
			$fail = true;
496
		// Trying to change passwords, slow us down, or something?
497
		elseif (strpos($clean, 'sleep') !== false && preg_match('~(^|[^a-z])sleep($|[^[_a-z])~s', $clean) != 0)
498
			$fail = true;
499
		elseif (strpos($clean, 'benchmark') !== false && preg_match('~(^|[^a-z])benchmark($|[^[a-z])~s', $clean) != 0)
500
			$fail = true;
501
502
		if (!empty($fail) && function_exists('log_error'))
503
			smf_db_error_backtrace('Hacking attempt...', 'Hacking attempt...' . "\n" . $db_string, E_USER_ERROR, __FILE__, __LINE__);
504
	}
505
506
	if (empty($db_unbuffered))
507
		$ret = @mysqli_query($connection, $db_string);