summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/cron/compat.c9
-rw-r--r--usr.sbin/cron/crontab.c9
-rw-r--r--usr.sbin/cron/entry.c52
-rw-r--r--usr.sbin/cron/env.c32
-rw-r--r--usr.sbin/cron/externs.h1
-rw-r--r--usr.sbin/cron/job.c5
-rw-r--r--usr.sbin/cron/misc.c5
-rw-r--r--usr.sbin/cron/user.c29
8 files changed, 114 insertions, 28 deletions
diff --git a/usr.sbin/cron/compat.c b/usr.sbin/cron/compat.c
index 492a16e024d..eb69fcd9c23 100644
--- a/usr.sbin/cron/compat.c
+++ b/usr.sbin/cron/compat.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: compat.c,v 1.1 1995/10/18 08:47:30 deraadt Exp $";
+static char rcsid[] = "$Id: compat.c,v 1.2 1996/11/01 23:27:28 millert Exp $";
#endif
/* vix 30dec93 [broke this out of misc.c - see RCS log for history]
@@ -53,7 +53,10 @@ strdup(str)
{
char *temp;
- temp = malloc(strlen(str) + 1);
+ if ((temp = malloc(strlen(str) + 1)) == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
(void) strcpy(temp, str);
return temp;
}
@@ -227,7 +230,7 @@ setenv(name, value, overwrite)
return -1;
}
- sprintf("%s=%s", name, value);
+ sprintf(tmp, "%s=%s", name, value);
return putenv(tmp); /* intentionally orphan 'tmp' storage */
}
#endif
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c
index 561e11edf81..e485e33f7fe 100644
--- a/usr.sbin/cron/crontab.c
+++ b/usr.sbin/cron/crontab.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: crontab.c,v 1.5 1996/10/31 03:10:55 millert Exp $";
+static char rcsid[] = "$Id: crontab.c,v 1.6 1996/11/01 23:27:30 millert Exp $";
#endif
/* crontab - install and manage per-user crontab files
@@ -321,7 +321,7 @@ edit_cmd() {
}
um = umask(077);
- (void) sprintf(Filename, "/tmp/crontab.XXXXXXXX");
+ (void) sprintf(Filename, "/tmp/crontab.XXXXXXXXXX");
if ((t = mkstemp(Filename)) == -1) {
perror(Filename);
(void) umask(um);
@@ -505,6 +505,11 @@ replace_cmd() {
time_t now = time(NULL);
char **envp = env_init();
+ if (envp == NULL) {
+ fprintf(stderr, "%s: Cannot allocate memory.\n", ProgramName);
+ return (-2);
+ }
+
(void) sprintf(n, "tmp.%d", Pid);
(void) sprintf(tn, CRON_TAB(n));
if (!(tmp = fopen(tn, "w+"))) {
diff --git a/usr.sbin/cron/entry.c b/usr.sbin/cron/entry.c
index 448924ada2f..7c2b4c12b67 100644
--- a/usr.sbin/cron/entry.c
+++ b/usr.sbin/cron/entry.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: entry.c,v 1.1 1995/10/18 08:47:30 deraadt Exp $";
+static char rcsid[] = "$Id: entry.c,v 1.2 1996/11/01 23:27:32 millert Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
@@ -91,6 +91,7 @@ load_entry(file, error_func, pw, envp)
int ch;
char cmd[MAX_COMMAND];
char envstr[MAX_ENVSTR];
+ char **tenvp;
Debug(DPARS, ("load_entry()...about to eat comments\n"))
@@ -247,24 +248,52 @@ load_entry(file, error_func, pw, envp)
/* copy and fix up environment. some variables are just defaults and
* others are overrides.
*/
- e->envp = env_copy(envp);
+ if ((e->envp = env_copy(envp)) == NULL) {
+ ecode = e_none;
+ goto eof;
+ }
if (!env_get("SHELL", e->envp)) {
sprintf(envstr, "SHELL=%s", _PATH_BSHELL);
- e->envp = env_set(e->envp, envstr);
+ if ((tenvp = env_set(e->envp, envstr))) {
+ e->envp = tenvp;
+ } else {
+ ecode = e_none;
+ goto eof;
+ }
}
if (!env_get("HOME", e->envp)) {
sprintf(envstr, "HOME=%s", pw->pw_dir);
- e->envp = env_set(e->envp, envstr);
+ if ((tenvp = env_set(e->envp, envstr))) {
+ e->envp = tenvp;
+ } else {
+ ecode = e_none;
+ goto eof;
+ }
}
if (!env_get("PATH", e->envp)) {
sprintf(envstr, "PATH=%s", _PATH_DEFPATH);
- e->envp = env_set(e->envp, envstr);
+ if ((tenvp = env_set(e->envp, envstr))) {
+ e->envp = tenvp;
+ } else {
+ ecode = e_none;
+ goto eof;
+ }
}
sprintf(envstr, "%s=%s", "LOGNAME", pw->pw_name);
- e->envp = env_set(e->envp, envstr);
+ if ((tenvp = env_set(e->envp, envstr))) {
+ e->envp = tenvp;
+ } else {
+ ecode = e_none;
+ goto eof;
+ }
#if defined(BSD)
sprintf(envstr, "%s=%s", "USER", pw->pw_name);
- e->envp = env_set(e->envp, envstr);
+ if ((tenvp = env_set(e->envp, envstr))) {
+ e->envp = tenvp;
+ } else {
+ ecode = e_none;
+ goto eof;
+ }
#endif
Debug(DPARS, ("load_entry()...about to parse command\n"))
@@ -285,7 +314,10 @@ load_entry(file, error_func, pw, envp)
/* got the command in the 'cmd' string; save it in *e.
*/
- e->cmd = strdup(cmd);
+ if ((e->cmd = strdup(cmd)) == NULL) {
+ ecode = e_none;
+ goto eof;
+ }
Debug(DPARS, ("load_entry()...returning successfully\n"))
@@ -294,6 +326,10 @@ load_entry(file, error_func, pw, envp)
return e;
eof:
+ if (e->envp)
+ env_free(e->envp);
+ if (e->cmd)
+ free(e->cmd);
free(e);
if (ecode != e_none && error_func)
(*error_func)(ecodes[(int)ecode]);
diff --git a/usr.sbin/cron/env.c b/usr.sbin/cron/env.c
index e0e19e2755b..9b6f6444075 100644
--- a/usr.sbin/cron/env.c
+++ b/usr.sbin/cron/env.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: env.c,v 1.3 1996/10/25 20:36:56 deraadt Exp $";
+static char rcsid[] = "$Id: env.c,v 1.4 1996/11/01 23:27:33 millert Exp $";
#endif
@@ -28,7 +28,8 @@ env_init()
{
register char **p = (char **) malloc(sizeof(char **));
- p[0] = NULL;
+ if (p)
+ p[0] = NULL;
return (p);
}
@@ -55,8 +56,18 @@ env_copy(envp)
for (count = 0; envp[count] != NULL; count++)
;
p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */
+ if (p == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
for (i = 0; i < count; i++)
- p[i] = strdup(envp[i]);
+ if ((p[i] = strdup(envp[i])) == NULL) {
+ while (--i >= 0)
+ (void) free(p[i]);
+ free(p);
+ errno = ENOMEM;
+ return NULL;
+ }
p[count] = NULL;
return (p);
}
@@ -87,7 +98,11 @@ env_set(envp, envstr)
* save our new one there, and return the existing array.
*/
free(envp[found]);
- envp[found] = strdup(envstr);
+ if ((envp[found] = strdup(envstr)) == NULL) {
+ envp[found] = "";
+ errno = ENOMEM;
+ return NULL;
+ }
return (envp);
}
@@ -98,8 +113,15 @@ env_set(envp, envstr)
*/
p = (char **) realloc((void *) envp,
(unsigned) ((count+1) * sizeof(char **)));
+ if (p == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
p[count] = p[count-1];
- p[count-1] = strdup(envstr);
+ if ((p[count-1] = strdup(envstr)) == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
return (p);
}
diff --git a/usr.sbin/cron/externs.h b/usr.sbin/cron/externs.h
index 3efe605897e..5d104302279 100644
--- a/usr.sbin/cron/externs.h
+++ b/usr.sbin/cron/externs.h
@@ -20,6 +20,7 @@
# include <unistd.h>
# include <string.h>
# include <dirent.h>
+# include <errno.h>
# define DIR_T struct dirent
# define WAIT_T int
# define WAIT_IS_INT 1
diff --git a/usr.sbin/cron/job.c b/usr.sbin/cron/job.c
index e1097cad102..18e96b6e36b 100644
--- a/usr.sbin/cron/job.c
+++ b/usr.sbin/cron/job.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: job.c,v 1.1 1995/10/18 08:47:30 deraadt Exp $";
+static char rcsid[] = "$Id: job.c,v 1.2 1996/11/01 23:27:36 millert Exp $";
#endif
@@ -45,7 +45,8 @@ job_add(e, u)
if (j->e == e && j->u == u) { return; }
/* build a job queue element */
- j = (job*)malloc(sizeof(job));
+ if ((j = (job*)malloc(sizeof(job))) == NULL)
+ return;
j->next = (job*) NULL;
j->e = e;
j->u = u;
diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c
index 160a0cd1896..4b78d69a227 100644
--- a/usr.sbin/cron/misc.c
+++ b/usr.sbin/cron/misc.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: misc.c,v 1.1 1995/10/18 08:47:30 deraadt Exp $";
+static char rcsid[] = "$Id: misc.c,v 1.2 1996/11/01 23:27:37 millert Exp $";
#endif
/* vix 26jan87 [RCS has the rest of the log]
@@ -622,7 +622,8 @@ mkprints(src, len)
{
register char *dst = malloc(len*4 + 1);
- mkprint(dst, src, len);
+ if (dst)
+ mkprint(dst, src, len);
return dst;
}
diff --git a/usr.sbin/cron/user.c b/usr.sbin/cron/user.c
index e03d07861f6..a2ce35bfed2 100644
--- a/usr.sbin/cron/user.c
+++ b/usr.sbin/cron/user.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: user.c,v 1.1 1995/10/18 08:47:31 deraadt Exp $";
+static char rcsid[] = "$Id: user.c,v 1.2 1996/11/01 23:27:39 millert Exp $";
#endif
/* vix 26jan87 [log is in RCS file]
@@ -52,7 +52,7 @@ load_user(crontab_fd, pw, name)
user *u;
entry *e;
int status;
- char **envp;
+ char **envp, **tenvp;
if (!(file = fdopen(crontab_fd, "r"))) {
perror("fdopen on crontab_fd in load_user");
@@ -63,14 +63,25 @@ load_user(crontab_fd, pw, name)
/* file is open. build user entry, then read the crontab file.
*/
- u = (user *) malloc(sizeof(user));
- u->name = strdup(name);
+ if ((u = (user *) malloc(sizeof(user))) == NULL) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ if ((u->name = strdup(name)) == NULL) {
+ free(u);
+ errno = ENOMEM;
+ return NULL;
+ }
u->crontab = NULL;
/*
* init environment. this will be copied/augmented for each entry.
*/
- envp = env_init();
+ if ((envp = env_init()) == NULL) {
+ free(u->name);
+ free(u);
+ return NULL;
+ }
/*
* load the crontab
@@ -89,7 +100,13 @@ load_user(crontab_fd, pw, name)
}
break;
case TRUE:
- envp = env_set(envp, envstr);
+ if ((tenvp = env_set(envp, envstr))) {
+ envp = tenvp;
+ } else {
+ free_user(u);
+ u = NULL;
+ goto done;
+ }
break;
}
}