Skip to content

Commit a217745

Browse files
Kristofer Älvringdahlerlend
authored andcommitted
Bug30416389 REVOKE ROLE WHEN USER HAS NO HOSTNAME
During lookup of the user, the hostname is set to nullptr. This patch replace the nullptr with an empty string. RB: 23229
1 parent 31d83fe commit a217745

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

mysql-test/r/roles2.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,17 @@ DROP DATABASE dddddb1;
508508
DROP DATABASE secdb1;
509509
DROP DATABASE secdb2;
510510
SET GLOBAL partial_revokes = @orig_partial_revokes;
511+
#
512+
# Empty hostnames not handled well
513+
#
514+
CREATE USER 'u1'@'' IDENTIFIED BY '123';
515+
GRANT SELECT ON *.* TO 'u1'@'';
516+
CREATE USER 'r1'@'' IDENTIFIED BY '123';
517+
CREATE USER 'r2'@'' IDENTIFIED BY '123';
518+
GRANT ROLE_ADMIN ON *.* TO current_user();
519+
GRANT 'r1'@'' TO 'u1'@'';
520+
GRANT 'r2'@'' TO 'u1'@'';
521+
SET DEFAULT ROLE 'r1'@'', 'r2'@'' TO 'u1'@'';
522+
REVOKE 'r1'@'' FROM 'u1'@'';
523+
REVOKE 'r2'@'' FROM 'u1'@'';
524+
DROP USER 'u1'@'','r1'@'','r2'@'';

mysql-test/t/roles2.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,3 +564,19 @@ disconnect con1;
564564
--disable_warnings
565565
SET GLOBAL partial_revokes = @orig_partial_revokes;
566566
--enable_warnings
567+
568+
--echo #
569+
--echo # Empty hostnames not handled well
570+
--echo #
571+
CREATE USER 'u1'@'' IDENTIFIED BY '123';
572+
GRANT SELECT ON *.* TO 'u1'@'';
573+
CREATE USER 'r1'@'' IDENTIFIED BY '123';
574+
CREATE USER 'r2'@'' IDENTIFIED BY '123';
575+
GRANT ROLE_ADMIN ON *.* TO current_user();
576+
GRANT 'r1'@'' TO 'u1'@'';
577+
GRANT 'r2'@'' TO 'u1'@'';
578+
SET DEFAULT ROLE 'r1'@'', 'r2'@'' TO 'u1'@'';
579+
REVOKE 'r1'@'' FROM 'u1'@'';
580+
REVOKE 'r2'@'' FROM 'u1'@'';
581+
DROP USER 'u1'@'','r1'@'','r2'@'';
582+

sql/auth/sql_auth_cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class ACL_HOST_AND_IP {
7979
public:
8080
ACL_HOST_AND_IP()
8181
: hostname(nullptr), hostname_length(0), ip(0), ip_mask(0) {}
82-
const char *get_host() const { return hostname; }
82+
const char *get_host() const { return hostname ? hostname : ""; }
8383
size_t get_host_len() const { return hostname_length; }
8484

8585
bool has_wildcard() {
86-
return (strchr(hostname, wild_many) || strchr(hostname, wild_one) ||
86+
return (strchr(get_host(), wild_many) || strchr(get_host(), wild_one) ||
8787
ip_mask);
8888
}
8989

0 commit comments

Comments
 (0)