]> granicus.if.org Git - mutt/commitdiff
Fix mutt_parse_rfc822_line() if lastp parameter is NULL.
authorKevin McCarthy <kevin@8t8.us>
Sun, 9 Dec 2018 20:32:24 +0000 (12:32 -0800)
committerKevin McCarthy <kevin@8t8.us>
Mon, 10 Dec 2018 01:41:00 +0000 (17:41 -0800)
It checked at the beginning before dereferencing, but not at the end.

Since lastp is only used for the user_hdrs case, move the local
variable and assignment inside that block to make it clear.

parse.c

diff --git a/parse.c b/parse.c
index c862328d39e0e57be45b7238691c60ed0ecebe12..75254958f008495cab876a1db68d202adbb5129e 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1015,10 +1015,6 @@ int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p, short
                            short do_2047, LIST **lastp)
 {
   int matched = 0;
-  LIST *last = NULL;
-  
-  if (lastp)
-    last = *lastp;
   
   switch (ascii_tolower (line[0]))
   {
@@ -1316,9 +1312,14 @@ int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p, short
   /* Keep track of the user-defined headers */
   if (!matched && user_hdrs)
   {
+    LIST *last = NULL;
+
+    if (lastp)
+      last = *lastp;
+
     /* restore the original line */
     line[strlen (line)] = ':';
-    
+
     if (weed && option (OPTWEED) && mutt_matches_ignore (line, Ignore)
        && !mutt_matches_ignore (line, UnIgnore))
       goto done;
@@ -1333,11 +1334,12 @@ int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p, short
     last->data = safe_strdup (line);
     if (do_2047)
       rfc2047_decode (&last->data);
+
+    if (lastp)
+      *lastp = last;
   }
 
   done:
-  
-  *lastp = last;
   return matched;
 }