Code Duplication    Length = 45-45 lines in 2 locations

Sources/Subs-Db-postgresql.php 1 location

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

Sources/Subs-Db-mysql.php 1 location

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