Skip to content

getname segfaults on an input string lacking a final '>' #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xipmix opened this issue Jun 17, 2013 · 0 comments
Open

getname segfaults on an input string lacking a final '>' #1

xipmix opened this issue Jun 17, 2013 · 0 comments

Comments

@xipmix
Copy link

xipmix commented Jun 17, 2013

patch below.

getname() - avoid segfault when parsing email address

When searching for "comments" containing a person's name (eg "Fred Nurk")
after an email address (eg <[email protected]>) it is possible that the
trailing > is missing. This can be caused by spamify_replacedomain() not
being careful enough in how it substitutes the domain name. In such cases
strchr() will return a value that could cause a segfault, so take a little
care that we have something valid before attempting to find the comment
segment of the header line.

In some cases the closing '>' of an email address may be missing.

diff --git a/src/getname.c b/src/getname.c
index 740ebc5..2001cd3 100644
--- a/src/getname.c
+++ b/src/getname.c
@@ -249,12 +249,15 @@ void getname(char *line, char **namep, char **emailp)
         }
         else if (*c == '<') {    /* Comment may be on the end */
             /* From: <[email protected]> Bill Campbell */
-            c = strchr(line, '>') + 1;
-            for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\n' && i < len; c++)
-                name[i++] = *c;
-
-            comment_fnd = 1;
+            if (strchr(line, '>')) {
+                c = strchr(line, '>') + 1;
+                for (i = 0, len = NAMESTRLEN - 1; *c && *c != '\n' && i < len; c++)
+                    name[i++] = *c;
+ 
+                comment_fnd = 1;
+            }
     }
+
     }
     else if (strchr(line, '(')) {
         c = strchr(line, '(');
--
1.7.2.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant