(mail_execute): Restore argv[0] before exiting, else argcv_free coredumps.
Showing
1 changed file
with
24 additions
and
14 deletions
... | @@ -62,10 +62,16 @@ mail_execute (int shell, int argc, char **argv) | ... | @@ -62,10 +62,16 @@ mail_execute (int shell, int argc, char **argv) |
62 | { | 62 | { |
63 | pid_t pid; | 63 | pid_t pid; |
64 | char *buf = NULL; | 64 | char *buf = NULL; |
65 | char *argv0 = NULL; | ||
65 | 66 | ||
66 | /* Skip leading whitespace from argv[0] */ | 67 | if (argc) |
67 | while (isspace (**argv)) | 68 | { |
68 | (*argv)++; | 69 | argv0 = argv[0]; |
70 | |||
71 | /* Skip leading whitespace from argv[0] */ | ||
72 | while (isspace (**argv)) | ||
73 | (*argv)++; | ||
74 | } | ||
69 | 75 | ||
70 | /* Expand arguments if required */ | 76 | /* Expand arguments if required */ |
71 | if (util_getenv (NULL, "bang", Mail_env_boolean, 0) == 0) | 77 | if (util_getenv (NULL, "bang", Mail_env_boolean, 0) == 0) |
... | @@ -77,7 +83,7 @@ mail_execute (int shell, int argc, char **argv) | ... | @@ -77,7 +83,7 @@ mail_execute (int shell, int argc, char **argv) |
77 | } | 83 | } |
78 | 84 | ||
79 | /* Construct command line and save it to gnu-last-command variable */ | 85 | /* Construct command line and save it to gnu-last-command variable */ |
80 | argcv_string (argc, &argv[0], &buf); | 86 | argcv_string (argc, argv, &buf); |
81 | util_setenv ("gnu-last-command", buf, Mail_env_string, 1); | 87 | util_setenv ("gnu-last-command", buf, Mail_env_string, 1); |
82 | 88 | ||
83 | /* Do actual work */ | 89 | /* Do actual work */ |
... | @@ -111,18 +117,22 @@ mail_execute (int shell, int argc, char **argv) | ... | @@ -111,18 +117,22 @@ mail_execute (int shell, int argc, char **argv) |
111 | execvp (argv[0], argv); | 117 | execvp (argv[0], argv); |
112 | exit (1); | 118 | exit (1); |
113 | } | 119 | } |
114 | else if (pid > 0) | 120 | else |
115 | { | ||
116 | free (buf); | ||
117 | while (waitpid (pid, NULL, 0) == -1) | ||
118 | /* do nothing */; | ||
119 | return 0; | ||
120 | } | ||
121 | else if (pid < 0) | ||
122 | { | 121 | { |
122 | if (argv0) /* Restore argv[0], else argcv_free will coredump */ | ||
123 | argv[0] = argv0; | ||
123 | free (buf); | 124 | free (buf); |
124 | mu_error ("fork failed: %s", mu_strerror (errno)); | 125 | if (pid > 0) |
125 | return 1; | 126 | { |
127 | while (waitpid (pid, NULL, 0) == -1) | ||
128 | /* do nothing */; | ||
129 | return 0; | ||
130 | } | ||
131 | else /* if (pid < 0) */ | ||
132 | { | ||
133 | mu_error ("fork failed: %s", mu_strerror (errno)); | ||
134 | return 1; | ||
135 | } | ||
126 | } | 136 | } |
127 | } | 137 | } |
128 | 138 | ... | ... |
-
Please register or sign in to post a comment