imap-send: handle missing response codes gracefully
authorRené Scharfe <l.s.r@web.de>
Thu, 2 Nov 2017 17:27:05 +0000 (18:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Nov 2017 13:45:57 +0000 (22:45 +0900)
Response codes are optional. Exit parse_response_code() early if it's
passed a NULL string, indicating that we reached the end of the reply.
This avoids dereferencing said NULL pointer.

Noticed-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
imap-send.c
index ffbf266b2fe9d3940ee66514a422dc8a08cdc8b5..efa6af4b511219821875414def17dd2b727228fc 100644 (file)
@@ -683,7 +683,7 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
        struct imap *imap = ctx->imap;
        char *arg, *p;
 
-       if (*s != '[')
+       if (!s || *s != '[')
                return RESP_OK;         /* no response code */
        s++;
        if (!(p = strchr(s, ']'))) {