From db3898898e0706b3c6d16cbc4e03e99305efd47c Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Sat, 23 Feb 2013 03:12:43 +0000 Subject: [PATCH] use of sscanf() had undefined behavior, replace with simple parsing instead see #3636 --- pop.c | 11 ++++++++++- pop_lib.c | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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)) -- 2.40.0