From: Thomas Roessler Date: Wed, 18 Apr 2001 15:12:50 +0000 (+0000) Subject: Fix a segmentation fault. Bug reported by Björn Jacke and analyzed X-Git-Tag: mutt-1-3-18-rel~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab49677b0be1df82222e75f176fec631e8714f73;p=mutt Fix a segmentation fault. Bug reported by Björn Jacke and analyzed by Lars Hecking. --- diff --git a/sendlib.c b/sendlib.c index d6093369..532f4094 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1650,21 +1650,27 @@ static void encode_headers (LIST *h) { char *tmp; char *p; - + int i; + for (; h; h = h->next) { - if ((p = strchr (h->data, ':'))) - { - *p++ = 0; - SKIPWS (p); - tmp = safe_strdup (p); - rfc2047_encode_string (&tmp); - safe_realloc ((void **) &h->data, - strlen (h->data) + 2 + strlen (tmp) + 1); - strcat (h->data, ": "); /* __STRCAT_CHECKED__ */ - strcat (h->data, tmp); /* __STRCAT_CHECKED__ */ - safe_free ((void **) &tmp); - } + if (!(p = strchr (h->data, ':'))) + continue; + + i = p - h->data; + ++p; SKIPWS (p); + tmp = safe_strdup (p); + + if (!tmp) + continue; + + rfc2047_encode_string (&tmp); + safe_realloc ((void **) &h->data, + mutt_strlen (h->data) + 2 + mutt_strlen (tmp) + 1); + + sprintf (h->data + i, ": %s", NONULL (tmp)); /* __SPRINTF_CHECKED__ */ + + safe_free ((void **) &tmp); } }