diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-04-14 18:21:52 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-04-14 18:21:52 +0300 |
commit | 77b116b12786c1f9520e87868528494db61ce8af (patch) | |
tree | 1909e33df7c5a406b7fc4079730c28eef8164cb1 /mailbox/rfc2047.c | |
parent | 94adc8f49244e0abfd3ac47e0cfb2af2a063adc5 (diff) | |
download | mailutils-77b116b12786c1f9520e87868528494db61ce8af.tar.gz mailutils-77b116b12786c1f9520e87868528494db61ce8af.tar.bz2 |
Fix memory leak in mu_rfc2047_decode.
* mailbox/rfc2047.c (getword): Change signature; return error
code.
(mu_rfc2047_decode): Reflect the above change.
Diffstat (limited to 'mailbox/rfc2047.c')
-rw-r--r-- | mailbox/rfc2047.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/mailbox/rfc2047.c b/mailbox/rfc2047.c index ba11d5808..64327d9cc 100644 --- a/mailbox/rfc2047.c +++ b/mailbox/rfc2047.c @@ -42,23 +42,26 @@ realloc_buffer (char **bufp, size_t *bufsizep, size_t incr) return 0; } -static char * -getword (const char **pstr, int delim) +int +getword (char **pret, const char **pstr, int delim) { size_t len; char *ret; const char *start = *pstr; const char *end = strchr (start, delim); + + free (*pret); if (!end) - return NULL; + return MU_ERR_BAD_2047_INPUT; len = end - start; ret = malloc (len + 1); if (!ret) - return NULL; + return ENOMEM; memcpy (ret, start, len); ret[len] = 0; *pstr = end + 1; - return ret; + *pret = ret; + return 0; } int @@ -119,23 +122,21 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) const char *sp = fromstr + 2; char tmp[128]; - fromcode = getword (&sp, '?'); - encoding_type = getword (&sp, '?'); - encoded_text = getword (&sp, '?'); + status = getword (&fromcode, &sp, '?'); + if (status) + break; + status = getword (&encoding_type, &sp, '?'); + if (status) + break; + status = getword (&encoded_text, &sp, '?'); + if (status) + break; if (sp == NULL || sp[0] != '=') { status = MU_ERR_BAD_2047_INPUT; break; } - if (fromcode == NULL - || encoding_type == NULL - || encoded_text == NULL) - { - status = MU_ERR_BAD_2047_INPUT; - break; - } - size = strlen (encoded_text); switch (encoding_type[0]) |