From: Michael Elkins Date: Sat, 23 Feb 2013 03:12:43 +0000 (+0000) Subject: use of sscanf() had undefined behavior, replace with simple parsing instead X-Git-Tag: neomutt-20160307~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=db3898898e0706b3c6d16cbc4e03e99305efd47c;p=neomutt use of sscanf() had undefined behavior, replace with simple parsing instead see #3636 --- diff --git a/pop.c b/pop.c index 85c34d1d6..90d95b907 100644 --- a/pop.c +++ b/pop.c @@ -33,6 +33,7 @@ #include #include +#include #ifdef USE_HCACHE #define HC_FNAME "mutt" /* filename for hcache as POP lacks paths */ @@ -141,8 +142,16 @@ static int fetch_uidl (char *line, void *data) int i, index; CONTEXT *ctx = (CONTEXT *)data; POP_DATA *pop_data = (POP_DATA *)ctx->data; + char *endp; + + errno = 0; + index = strtol(line, &endp, 10); + if (errno) + return -1; + while (*endp == ' ') + endp++; + memmove(line, endp, strlen(endp) + 1); - sscanf (line, "%d %s", &index, line); for (i = 0; i < ctx->msgcount; i++) if (!mutt_strcmp (line, ctx->hdrs[i]->data)) break; diff --git a/pop_lib.c b/pop_lib.c index 62fea35ac..b7baf700f 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -32,6 +32,7 @@ #include #include #include +#include /* given an POP mailbox name, return host, port, username and password */ int pop_parse_path (const char* path, ACCOUNT* acct) @@ -523,8 +524,16 @@ static int check_uidl (char *line, void *data) int i; unsigned int index; CONTEXT *ctx = (CONTEXT *)data; + char *endp; + + errno = 0; + index = strtoul(line, &endp, 10); + if (errno) + return -1; + while (*endp == ' ') + endp++; + memmove(line, endp, strlen(endp) + 1); - sscanf (line, "%u %s", &index, line); for (i = 0; i < ctx->msgcount; i++) { if (!mutt_strcmp (ctx->hdrs[i]->data, line))