From 194ddc51be601d2d4945248b645d710e3eb0d637 Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Mon, 1 Jun 2009 11:27:07 +0200 Subject: [PATCH] SMTP: Use mutt_atoi() to parse server responses --- ChangeLog | 11 +++++++++++ smtp.c | 27 ++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3a9796f2..15a13add1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-06-01 11:26 +0200 Rocco Rutte (35a444838167) + + * curs_main.c, edit.c, init.c, main.c, menu.c, mh.c, parse.c, + resize.c, score.c, url.c: Use strtol() wrappers for most atoi() + calls + +2009-06-01 11:24 +0200 Rocco Rutte (f1b6eb09f2ad) + + * ChangeLog, lib.c, lib.h: Add mutt_atos(), mutt_atoi() and + mutt_atol() (strtol() wrappers) + 2009-06-01 10:36 +0200 Rocco Rutte (36b7e267ce33) * send.c: Treat address groups as no recipients diff --git a/smtp.c b/smtp.c index f6be5ee83..30221745f 100644 --- a/smtp.c +++ b/smtp.c @@ -47,6 +47,7 @@ #define smtp_err_read -2 #define smtp_err_write -3 +#define smtp_err_code -4 #define SMTP_PORT 25 #define SMTPS_PORT 465 @@ -76,6 +77,21 @@ static int Esmtp = 0; static char* AuthMechs = NULL; static unsigned char Capabilities[(CAPMAX + 7)/ 8]; +static int smtp_code (char *buf, size_t len, int *n) +{ + char code[3]; + + if (len < 4) + return -1; + code[0] = buf[0]; + code[1] = buf[1]; + code[2] = buf[2]; + code[3] = 0; + if (mutt_atoi (code, n) < 0) + return -1; + return 0; +} + /* Reads a command response from the SMTP server. * Returns: * 0 on success (2xx code) or continue (354 code) @@ -107,7 +123,9 @@ smtp_get_resp (CONNECTION * conn) else if (!ascii_strncasecmp ("STARTTLS", buf + 4, 8)) mutt_bit_set (Capabilities, STARTTLS); - n = atoi (buf); + if (smtp_code (buf, n, &n) < 0) + return smtp_err_code; + } while (buf[3] == '-'); if (smtp_success (n) || n == smtp_continue) @@ -290,6 +308,8 @@ mutt_smtp_send (const ADDRESS* from, const ADDRESS* to, const ADDRESS* cc, mutt_error (_("SMTP session failed: read error")); else if (ret == smtp_err_write) mutt_error (_("SMTP session failed: write error")); + else if (ret == smtp_err_code) + mutt_error (_("Invalid server response")); return ret; } @@ -546,9 +566,10 @@ static int smtp_auth_sasl (CONNECTION* conn, const char* mechlist) do { if (mutt_socket_write (conn, buf) < 0) goto fail; - if (mutt_socket_readln (buf, sizeof (buf), conn) < 0) + if ((rc = mutt_socket_readln (buf, sizeof (buf), conn)) < 0) + goto fail; + if (smtp_code (buf, rc, &rc) < 0) goto fail; - rc = atoi(buf); if (rc != smtp_ready) break; -- 2.40.0