From f267427a9cd245b476406f82823502f4279f450b Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 3 Feb 2014 15:47:49 +0100 Subject: [PATCH] AUTH PLAIN: second try. --- citadel/modules/imap/serv_imap.c | 24 +++++++++++++++++------- citadel/modules/smtp/serv_smtp.c | 27 ++++++++++++++++++++------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index 4b3e146ce..d33e66ee6 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 decoded_len; long len; 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; + } - len = safestrncpy(pass, decoded_authstring, sizeof pass); - if (len < 0) - len = sizeof(pass) - 1; + if (decoded_len > 0) + { + len = safestrncpy(pass, decoded_authstring, sizeof pass); + + if (len < 0) + len = sizeof(pass) - 1; + } } Imap->authstate = imap_as_normal; diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index ece85545f..760ea5a82 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -444,24 +444,37 @@ void smtp_try_plain(long offset, long Flags) char user[256] = ""; char pass[256] = ""; int result; + + long decoded_len; long len; - len = StrBufDecodeBase64(sSMTP->Cmd); - if (len > 0) + memset(pass, 0, sizeof(pass)); + decoded_len = StrBufDecodeBase64(sSMTP->Cmd); + + if (decoded_len > 0) { decoded_authstring = ChrPtr(sSMTP->Cmd); 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; + } } sSMTP->command_state = smtp_command; -- 2.30.2