source: trunk/dports/mail/ssmtp/files/patch-ssmtp.c @ 78915

Last change on this file since 78915 was 78915, checked in by jmr@…, 8 years ago

ssmtp: fix crash (#27673)

File size: 1.3 KB
Line 
1--- ssmtp.c.orig        2011-05-27 03:59:39.000000000 +1000
2+++ ssmtp.c     2011-05-27 04:01:21.000000000 +1000
3@@ -13,6 +13,7 @@
4 #define VERSION "2.64"
5 #define _GNU_SOURCE
6 
7+#include <sys/types.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <sys/param.h>
11@@ -24,6 +25,7 @@
12 #include <setjmp.h>
13 #include <string.h>
14 #include <ctype.h>
15+#include <libgen.h>
16 #include <netdb.h>
17 #ifdef HAVE_SSL
18 #include <openssl/crypto.h>
19@@ -2078,6 +2080,8 @@ main() -- make the program behave like s
20 int main(int argc, char **argv)
21 {
22        char **new_argv;
23+       char *tmp1;
24+       char *tmp2;
25 
26        /* Try to be bulletproof :-) */
27        (void)signal(SIGHUP, SIG_IGN);
28@@ -2086,7 +2090,25 @@ int main(int argc, char **argv)
29        (void)signal(SIGTTOU, SIG_IGN);
30 
31        /* Set the globals */
32-       prog = basename(argv[0]);
33+       /* basename may write to its input string, so we can't give it argv;
34+          plus the string it returns isn't permanently malloc'd, so we have to
35+          make a copy */
36+       tmp1 = strdup(argv[0]);
37+       if (!tmp1) {
38+           perror("strdup");
39+           die("main: strdup()");
40+       }
41+       tmp2 = basename(tmp1);
42+       if (!tmp2) {
43+           perror("basename");
44+           die("main: basename()");
45+       }
46+       prog = strdup(tmp2);
47+       if (!prog) {
48+           perror("strdup");
49+           die("main: strdup()");
50+       }
51+       free(tmp1);
52 
53        hostname = xgethostname();
54 
Note: See TracBrowser for help on using the repository browser.