Skip to content

Commit

Permalink
net_imap: Add assertion guarding potential NULL dereference.
Browse files Browse the repository at this point in the history
There has been a single incident where there was a segfault
in this strncmp call, but not enough details at this point
to determine why this happened. Add some assertions for
the meantime to provide better visibility into this in the
future, should this happen again.

LBBS-14 #close
  • Loading branch information
InterLinked1 committed Sep 16, 2024
1 parent e842676 commit 4454e1d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nets/net_imap/imap_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,16 @@ static struct imap_client *__load_virtual_mailbox(struct imap_session *imap, con
size_t pathlen;

if (imap->client) {
const char *virtprefix = imap->client->virtprefix;
/* Reuse the same connection if it's the same account. */
if (!strncmp(imap->client->virtprefix, path, imap->client->virtprefixlen)) {
bbs_assert_exists(path);
bbs_assert_exists(virtprefix);
if (!strncmp(virtprefix, path, imap->client->virtprefixlen)) {
bbs_debug(5, "Reusing existing active connection for %s\n", path);
*exists = 1;
return imap->client;
}
/* An optimization here is if the remote server supports the UNAUTHENTICATE capability,
/* A potential optimization here is if the remote server supports the UNAUTHENTICATE capability,
* we can reuse the connection instead of establishing a new one
* (if it's the same server (hostname), but different user/account)
* Unfortunately, no major providers support the UNAUTHENTICATE extension,
Expand Down

0 comments on commit 4454e1d

Please sign in to comment.