]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
imap: Added stricter parsing of tagged command responses
authorJiri Hruska <jirka@fud.cz>
Sun, 24 Feb 2013 11:48:43 +0000 (12:48 +0100)
committerSteve Holme <steve_holme@hotmail.com>
Sun, 24 Feb 2013 12:02:59 +0000 (12:02 +0000)
Enhanced the parsing of tagged responses which must start with "OK",
"NO" or "BAD"

lib/imap.c

index 3a9ee45a94d5d2b87e36fd23b46fb13415f82d19..559ae0bbaa50c4564faef6c9e6589e1e5ed17a7c 100644 (file)
@@ -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;
   }