diff --git a/anacron/runjob.c b/anacron/runjob.c index 050ef20..57ee83f 100644 --- a/anacron/runjob.c +++ b/anacron/runjob.c @@ -322,6 +322,10 @@ launch_job(job_rec *jr) complain("The environment variable 'MAILTO' could not be expanded. The non-expanded value will be used."); } } + if (mailto != NULL && (mailto = strdup(mailto)) == NULL) { + complain("Strdup failed for MAILTO, job not run"); + return; + } /* Get the source email address if set, or current user otherwise */ mailfrom = getenv("MAILFROM"); @@ -361,7 +365,6 @@ launch_job(job_rec *jr) if (*mailto == '\0') jr->mailto = NULL; else - /* ugly but works without strdup() */ jr->mailto = mailto; jr->mail_header_size = file_size(fd); diff --git a/src/crontab.c b/src/crontab.c index 55d2aed..bd198f7 100644 --- a/src/crontab.c +++ b/src/crontab.c @@ -766,7 +766,7 @@ static void edit_cmd(void) { if (ferror(NewCrontab)) { fprintf(stderr, "%s: error while writing new crontab to %s\n", ProgramName, Filename); - fatal: + fatal: unlink(Filename); exit(ERROR_EXIT); } @@ -776,6 +776,11 @@ static void edit_cmd(void) { editor = EDITOR; } + if (!glue_strings(q, sizeof q, editor, Filename, ' ')) { + fprintf(stderr, "%s: %s command line too long\n", ProgramName, editor); + goto fatal; + } + /* we still have the file open. editors will generally rewrite the * original file rather than renaming/unlinking it and starting a * new one; even backup files are supposed to be made by copying @@ -798,10 +803,6 @@ static void edit_cmd(void) { perror("setuid(getuid())"); exit(ERROR_EXIT); } - if (!glue_strings(q, sizeof q, editor, Filename, ' ')) { - fprintf(stderr, "%s: editor command line too long\n", ProgramName); - exit(ERROR_EXIT); - } execlp(_PATH_BSHELL, _PATH_BSHELL, "-c", q, (char *) 0); perror(editor); exit(ERROR_EXIT); @@ -901,7 +902,7 @@ static void edit_cmd(void) { } } /*NOTREACHED*/ case -2: - abandon: + abandon: fprintf(stderr, "%s: edits left in %s\n", ProgramName, Filename); goto done; default: