Skip to content

Commit

Permalink
Avoid keeping the return value of getenv for prolonged time
Browse files Browse the repository at this point in the history
Fixes #185
  • Loading branch information
t8m committed Jul 11, 2024
1 parent b3a54d0 commit fd466b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion anacron/runjob.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions src/crontab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fd466b6

Please sign in to comment.