Skip to content

Commit

Permalink
mboxlist: better dbname/key INBOX bounds checking
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Dec 6, 2024
1 parent 97339e4 commit 4e5c1ea
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions imap/mboxlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ static void mboxlist_dbname_to_key(const char *dbname, size_t len,
char *inbox = mbname_dbname(mbname);
size_t inboxlen = strlen(inbox);

if (len >= inboxlen && !strncmp(dbname, inbox, inboxlen)) {
if (len >= inboxlen
&& (!dbname[inboxlen] || dbname[inboxlen] == DB_HIERSEP_CHAR)
&& !strncmp(dbname, inbox, inboxlen))
{
buf_appendcstr(key, "INBOX");
dbname += inboxlen;
len -= inboxlen;
Expand All @@ -394,7 +397,13 @@ static void mboxlist_dbname_to_key(const char *dbname, size_t len,
static void mboxlist_dbname_from_key(const char *key, size_t len,
const char *userid, struct buf *dbname)
{
if (userid && len >= 6 && !strncmp(key+1, "INBOX", 5)) {
assert(key[0] == KEY_TYPE_NAME);

if (userid
&& len >= 6
&& (!key[6] || key[6] == DB_HIERSEP_CHAR)
&& !strncmp(key+1, "INBOX", 5))
{
mbname_t *mbname = mbname_from_userid(userid);
char *inbox = mbname_dbname(mbname);

Expand Down

0 comments on commit 4e5c1ea

Please sign in to comment.