aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--smtp.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/smtp.c b/smtp.c
index 9ca93813..6e59ac4b 100644
--- a/smtp.c
+++ b/smtp.c
@@ -117,11 +117,14 @@ static void SMTP_auth(int sock, char smtp_mode, char *username, char *password,
snprintf(tmp, sizeof(tmp), "^%s^%s", username, password);
len = strlen(tmp);
- for (c = len - 1; c >= 0; c--)
- {
- if (tmp[c] == '^')
- tmp[c] = '\0';
- }
+
+ /* Take care not to overflow the buffer */
+ c = 0;
+ tmp[c] = '\0';
+ c += 1 + strlen(username);
+ if (c < len)
+ tmp[c] = '\0';
+
to64frombits(b64buf, tmp, len, sizeof b64buf);
SockPrintf(sock, "AUTH PLAIN %s\r\n", b64buf);
SMTP_ok(sock, smtp_mode, TIMEOUT_DEFAULT);