Skip to content

Commit

Permalink
CacheDB: Allow "," in URL passwords
Browse files Browse the repository at this point in the history
Many thanks to @xuxin010033 for the report!

Fixes #2786

(cherry picked from commit f904694)
  • Loading branch information
liviuchircu committed Nov 16, 2022
1 parent 2ebd84e commit d3df2e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cachedb/cachedb_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ static int parse_cachedb_url(struct cachedb_id* id, const str* url)
break;

case ',':
/* password could have a "," -> do a look-ahead to confirm */
if (q_memchr(url->s + i, '@', len - i))
continue;

st=ST_HOST;
start_host=start_prev;
id->flags |= CACHEDB_ID_MULTIPLE_HOSTS;
Expand Down
11 changes: 11 additions & 0 deletions cachedb/test/test_cachedb.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ static void test_cachedb_url(void)
/* invalid URLs */
ok(!new_cachedb_id(_str("d:g://@")));
ok(!new_cachedb_id(_str("d:g://u:@")));
ok(!new_cachedb_id(_str("d:g://u:p")));
ok(!new_cachedb_id(_str("d:g://u:p@")));
ok(!new_cachedb_id(_str("d:g://u:p@h:")));

Expand Down Expand Up @@ -706,4 +707,14 @@ static void test_cachedb_url(void)
ok(!strcmp(db->host, "h1,h2,h3:6379"));
ok(!strcmp(db->database, "d"));
ok(db->port == 0);

/* special chars in password */

CDB_PARSE("redis:group1://:,pwd,foo,@h1,h2,h3:6379/d");
ok(db->flags == CACHEDB_ID_MULTIPLE_HOSTS);
ok(!strcmp(db->username, ""));
ok(!strcmp(db->password, ",pwd,foo,"));
ok(!strcmp(db->host, "h1,h2,h3:6379"));
ok(!strcmp(db->database, "d"));
ok(db->port == 0);
}

0 comments on commit d3df2e2

Please sign in to comment.