diff options
author | Jiri Hruska <jirka@fud.cz> | 2013-02-24 12:48:43 +0100 |
---|---|---|
committer | Steve Holme <steve_holme@hotmail.com> | 2013-02-24 12:02:59 +0000 |
commit | 66149248ba8af1f711c6cb6b1522b050515ad529 (patch) | |
tree | 3ad786e1388bf6f36b7add40e60db2c47f7d8b37 | |
parent | c38d69f06a175ca6a92c3792d18630529a9357c2 (diff) |
imap: Added stricter parsing of tagged command responses
Enhanced the parsing of tagged responses which must start with "OK",
"NO" or "BAD"
-rw-r--r-- | lib/imap.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/imap.c b/lib/imap.c index 3a9ee45a9..559ae0bba 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -335,8 +335,19 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len, size_t wordlen; /* Do we have a tagged command response? */ - if(len >= id_len + 3 && !memcmp(id, line, id_len) && line[id_len] == ' ') { - *resp = line[id_len + 1]; /* O, N or B */ + if(len >= id_len + 1 && !memcmp(id, line, id_len) && line[id_len] == ' ') { + len = len - id_len - 1; + + if(len >= 2 && !memcmp(line + id_len + 1, "OK", 2)) + *resp = 'O'; + else if(len >= 2 && !memcmp(line + id_len + 1, "NO", 2)) + *resp = 'N'; + else if(len >= 3 && !memcmp(line + id_len + 1, "BAD", 3)) + *resp = 'B'; + else { + failf(conn->data, "Bad tagged response"); + *resp = -1; + } return TRUE; } |