X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fimap%2Fserv_imap.c;h=85751e69b08e47cea8381c69b845caaf5ebeaad4;hb=322cfa725de0599cd31aa1cbbba256e827e9a80a;hp=4b3e146cef6f40ef696311400cf4627811fe8f28;hpb=798de81c6bb695516dda1d32a324fff56b3fc0a6;p=citadel.git diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index 4b3e146ce..85751e69b 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -708,26 +708,36 @@ void imap_auth_plain(void) char user[256] = ""; char pass[256] = ""; int result; - long len; + long decoded_len; + long len = 0; memset(pass, 0, sizeof(pass)); - len = StrBufDecodeBase64(Imap->Cmd.CmdBuf); + decoded_len = StrBufDecodeBase64(Imap->Cmd.CmdBuf); - if (len > 0) + if (decoded_len > 0) { decoded_authstring = ChrPtr(Imap->Cmd.CmdBuf); len = safestrncpy(ident, decoded_authstring, sizeof ident); + decoded_len -= len - 1; decoded_authstring += len + 1; - len = safestrncpy(user, decoded_authstring, sizeof user); + if (decoded_len > 0) + { + len = safestrncpy(user, decoded_authstring, sizeof user); - decoded_authstring += len + 1; + decoded_authstring += len + 1; + decoded_len -= len - 1; + } + + if (decoded_len > 0) + { + len = safestrncpy(pass, decoded_authstring, sizeof pass); - len = safestrncpy(pass, decoded_authstring, sizeof pass); - if (len < 0) - len = sizeof(pass) - 1; + if (len < 0) + len = sizeof(pass) - 1; + } } Imap->authstate = imap_as_normal;