Skip to content

Commit fdae90d

Browse files
author
Arun Kuruvila
committed
Bug #20181776 :- ACCESS CONTROL DOESN'T MATCH MOST SPECIFIC
HOST WHEN IT CONTAINS WILDCARD Description :- Incorrect access privileges are provided to a user due to wrong sorting of users when wildcard characters is present in the hostname. Analysis :- Function "get_sorts()" is used to sort the strings of user name, hostname, database name. It is used to arrange the users in the access privilege matching order. When a user connects, it checks in the sorted user access privilege list and finds a corresponding matching entry for the user. Algorithm used in "get_sort()" sorts the strings inappropriately. As a result, when a user connects to the server, it is mapped to incorrect user access privileges. Algorithm used in "get_sort()" counts the number of characters before the first occurence of any one of the wildcard characters (single-wildcard character '_' or multi-wildcard character '%') and sorts in that order. As a result of inconnect sorting it treats hostname "%" and "%.mysql.com" as equally-specific values and therefore the order is indeterminate. Fix:- The "get_sort()" algorithm has been modified to treat "%" seperately. Now "get_sort()" returns a number which, if sorted in descending order, puts strings in the following order:- * strings with no wildcards * strings containg wildcards and non-wildcard characters * single muilt-wildcard character('%') * empty string.
1 parent c655515 commit fdae90d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sql/sql_acl.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,8 @@ static ulong get_access(TABLE *form, uint fieldnr, uint *next_field)
801801
/*
802802
Return a number which, if sorted 'desc', puts strings in this order:
803803
no wildcards
804-
wildcards
804+
strings containg wildcards and non-wildcard characters
805+
single muilt-wildcard character('%')
805806
empty string
806807
*/
807808

@@ -818,7 +819,16 @@ static ulong get_sort(uint count,...)
818819
{
819820
char *start, *str= va_arg(args,char*);
820821
uint chars= 0;
821-
uint wild_pos= 0; /* first wildcard position */
822+
uint wild_pos= 0;
823+
824+
/*
825+
wild_pos
826+
0 if string is empty
827+
1 if string is a single muilt-wildcard
828+
character('%')
829+
first wildcard position + 1 if string containg wildcards and
830+
non-wildcard characters
831+
*/
822832

823833
if ((start= str))
824834
{
@@ -829,6 +839,8 @@ static ulong get_sort(uint count,...)
829839
else if (*str == wild_many || *str == wild_one)
830840
{
831841
wild_pos= (uint) (str - start) + 1;
842+
if (!(wild_pos == 1 && *str == wild_many && *(++str) == '\0'))
843+
wild_pos++;
832844
break;
833845
}
834846
chars= 128; // Marker that chars existed

0 commit comments

Comments
 (0)