This looks good to me. Thank you, Viktor!
On 02/11/2015 06:39 PM, Viktor Dukhovni wrote:
On Wed, Feb 11, 2015 at 06:17:13PM -0800, Corey Ashford wrote:
From our reading of the code, tag can never be 0 there, so that makes the
"then" part of the if statement dead code.
After that, there's another if statement (line 254) that will always
evaluate as true:
if (tag != 0) {
...
In summary, I believe that removing the "tag = 0;" line was not the right
fix for the seg fault bug, but it's not clear to me what the right fix is.
I would:
diff --git a/src/postlog/postlog.c b/src/postlog/postlog.c
index 6384396..3c22180 100644
--- a/src/postlog/postlog.c
+++ b/src/postlog/postlog.c
@@ -170,7 +170,7 @@ MAIL_VERSION_STAMP_DECLARE;
int main(int argc, char **argv)
{
struct stat st;
- char *slash;
+ char *progname;
int fd;
int ch;
const char *tag;
@@ -200,10 +200,10 @@ int main(int argc, char **argv)
/*
* Set up diagnostics.
*/
- if ((slash = strrchr(argv[0], '/')) != 0 && slash[1])
- tag = mail_task(slash + 1);
+ if ((progname = strrchr(argv[0], '/')) != 0 && progname[1])
+ tag = mail_task(++progname);
else
- tag = mail_task(argv[0]);
+ tag = mail_task(progname = argv[0]);
if (isatty(STDERR_FILENO))
msg_vstream_init(tag, VSTREAM_ERR);
msg_syslog_init(tag, LOG_PID, LOG_FACILITY);
@@ -216,10 +216,12 @@ int main(int argc, char **argv)
/*
* Parse switches.
*/
+ tag = 0;
while ((ch = GETOPT(argc, argv, "c:ip:t:v")) > 0) {
switch (ch) {
default:
- msg_fatal("usage: %s [-c config_dir] [-i] [-p priority] [-t tag] [-v]
[text]", tag);
+ msg_fatal("usage: %s [-c config_dir] [-i] [-p priority] [-t tag]"
+ " [-v] [text]", progname);
break;
case 'c':
if (setenv(CONF_ENV_PATH, optarg, 1) < 0)
@@ -245,12 +247,8 @@ int main(int argc, char **argv)
* specified with msg_syslog_init();
*/
mail_conf_read();
- if (tag == 0 && strcmp(var_syslog_name, DEF_SYSLOG_NAME) != 0) {
- if ((slash = strrchr(argv[0], '/')) != 0 && slash[1])
- tag = mail_task(slash + 1);
- else
- tag = mail_task(argv[0]);
- }
+ if (tag == 0 && strcmp(var_syslog_name, DEF_SYSLOG_NAME) != 0)
+ tag = mail_task(progname);
/*
* Re-initialize the logging, this time with the tag specified in main.cf