From d9222b5f8fb29be6dea4f5d3a49acd3c3818668d Mon Sep 17 00:00:00 2001 From: pfg Date: Mon, 4 Jan 2016 03:20:41 +0000 Subject: MFC r292605, r292606, r292607, r292608: cron: bring some fixes for Coverity reports and other issues. crontab: replace malloc + bzero with calloc crontab: properly free an entry cron: Check the return value of pipe(2) CID: 271773, 1009830, --- usr.sbin/cron/cron/do_command.c | 6 ++++-- usr.sbin/cron/cron/popen.c | 3 +-- usr.sbin/cron/crontab/crontab.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c index fee4131..1ad8395 100644 --- a/usr.sbin/cron/cron/do_command.c +++ b/usr.sbin/cron/cron/do_command.c @@ -161,8 +161,10 @@ child_process(e, u) /* create some pipes to talk to our future child */ - pipe(stdin_pipe); /* child's stdin */ - pipe(stdout_pipe); /* child's stdout */ + if (pipe(stdin_pipe) != 0 || pipe(stdout_pipe) != 0) { + log_it("CRON", getpid(), "error", "can't pipe"); + exit(ERROR_EXIT); + } /* since we are a forked process, we can diddle the command string * we were passed -- nobody else is going to use it again, right? diff --git a/usr.sbin/cron/cron/popen.c b/usr.sbin/cron/cron/popen.c index 428de2e..57b1f77 100644 --- a/usr.sbin/cron/cron/popen.c +++ b/usr.sbin/cron/cron/popen.c @@ -82,9 +82,8 @@ cron_popen(program, type, e) if (!pids) { if ((fds = getdtablesize()) <= 0) return(NULL); - if (!(pids = (PID_T *)malloc((u_int)(fds * sizeof(PID_T))))) + if (!(pids = calloc(fds, sizeof(PID_T)))) return(NULL); - bzero((char *)pids, fds * sizeof(PID_T)); } if (pipe(pdes) < 0) return(NULL); diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c index 1ac81b0..f2e97a7 100644 --- a/usr.sbin/cron/crontab/crontab.c +++ b/usr.sbin/cron/crontab/crontab.c @@ -558,7 +558,7 @@ replace_cmd() { case FALSE: e = load_entry(tmp, check_error, pw, envp); if (e) - free(e); + free_entry(e); break; case TRUE: break; -- cgit v1.1