From e53b91fe52be262d94a45769814c1e87c796988b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 20 Oct 2011 08:43:44 +0200 Subject: Escape wildcards in "LIKE" patterns Percent signs ("%") and underscores ("_") are not escaped by mysql_real_escape_string() and are interpreted as wildcards if combined with "LIKE". Write a wrapper function db_escape_like() and use it where appropriate. Note that we already fixed this for the RPC interface in commit da2ebb667b7a332ddd8d905bf9b9a8694765fed6 but missed the other places. This patch should fix all remaining flaws reported in FS#26527. Signed-off-by: Lukas Fleischer Signed-off-by: Dan McGee --- web/lib/aur.inc.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'web/lib/aur.inc.php') diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 51c1eff7..6bc36ac5 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -229,6 +229,11 @@ function db_escape_string($string) { return mysql_real_escape_string($string); } +# Escape strings for usage in SQL LIKE operators. +function db_escape_like($string) { + return addcslashes(mysql_real_escape_string($string), '%_'); +} + # disconnect from the database # this won't normally be needed as PHP/reference counting will take care of # closing the connection once it is no longer referenced -- cgit v1.2.3-24-g4f1b