Skip to content

Commit f904694

Browse files
committed
CacheDB: Allow "," in URL passwords
Many thanks to @xuxin010033 for the report! Fixes #2786
1 parent bacb776 commit f904694

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

cachedb/cachedb_id.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ static int parse_cachedb_url(struct cachedb_id* id, const str* url)
210210
break;
211211

212212
case ',':
213+
/* password could have a "," -> do a look-ahead to confirm */
214+
if (q_memchr(url->s + i, '@', len - i))
215+
continue;
216+
213217
st=ST_HOST;
214218
start_host=start_prev;
215219
id->flags |= CACHEDB_ID_MULTIPLE_HOSTS;

cachedb/test/test_cachedb.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static void test_cachedb_url(void)
694694
/* invalid URLs */
695695
ok(!new_cachedb_id(_str("d:g://@")));
696696
ok(!new_cachedb_id(_str("d:g://u:@")));
697+
ok(!new_cachedb_id(_str("d:g://u:p")));
697698
ok(!new_cachedb_id(_str("d:g://u:p@")));
698699
ok(!new_cachedb_id(_str("d:g://u:p@h:")));
699700

@@ -875,4 +876,14 @@ static void test_cachedb_url(void)
875876
ok(!strcmp(db->host, "h1,h2,h3:6379"));
876877
ok(!strcmp(db->database, "d"));
877878
ok(db->port == 0);
879+
880+
/* special chars in password */
881+
882+
CDB_PARSE("redis:group1://:,pwd,foo,@h1,h2,h3:6379/d");
883+
ok(db->flags == CACHEDB_ID_MULTIPLE_HOSTS);
884+
ok(!strcmp(db->username, ""));
885+
ok(!strcmp(db->password, ",pwd,foo,"));
886+
ok(!strcmp(db->host, "h1,h2,h3:6379"));
887+
ok(!strcmp(db->database, "d"));
888+
ok(db->port == 0);
878889
}

0 commit comments

Comments
 (0)