summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron/lib
diff options
context:
space:
mode:
authorpst <pst@FreeBSD.org>1996-12-17 00:55:20 +0000
committerpst <pst@FreeBSD.org>1996-12-17 00:55:20 +0000
commit253df5b08a3b317eaf4a167361219cc2de05aa31 (patch)
tree19c4dd1a0d2247fce3e58d233ea6294b83fd819d /usr.sbin/cron/lib
parentf5dbed887331c9ef9a08faa00caa1cb9cfa9d579 (diff)
downloadFreeBSD-src-253df5b08a3b317eaf4a167361219cc2de05aa31.zip
FreeBSD-src-253df5b08a3b317eaf4a167361219cc2de05aa31.tar.gz
Replace my "inane" usage of snprintf to copy strings with strncpy as
used by OpenBSD. (Quite frankly, I think it's perfectly reasonable to use snprintf to copy strings, given that the semantics for strncpy() are utterly idiotic and there is no POSIX sstrncpy().) While I'm at it, incorporate some of OpenBSD's bugfixes to cron. NOT for 2.2
Diffstat (limited to 'usr.sbin/cron/lib')
-rw-r--r--usr.sbin/cron/lib/compat.c15
-rw-r--r--usr.sbin/cron/lib/env.c34
2 files changed, 38 insertions, 11 deletions
diff --git a/usr.sbin/cron/lib/compat.c b/usr.sbin/cron/lib/compat.c
index 87eeacc..eb69fcd 100644
--- a/usr.sbin/cron/lib/compat.c
+++ b/usr.sbin/cron/lib/compat.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: compat.c,v 1.1.1.1 1994/08/27 13:43:02 jkh 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;
}
@@ -143,7 +146,7 @@ getdtablesize() {
* Snarfage done by Jarkko Hietaniemi <Jarkko.Hietaniemi@hut.fi>
* *) well, almost, had to K&R the function entry, HPUX "cc"
* does not grok ANSI function prototypes */
-
+
/*
* flock (fd, operation)
*
@@ -199,13 +202,13 @@ flock(fd, operation)
case LOCK_UN: /* unlock */
i = lockf (fd, F_ULOCK, 0);
break;
-
+
default: /* can't decipher operation */
i = -1;
errno = EINVAL;
break;
}
-
+
return (i);
}
#endif /*NEED_FLOCK*/
@@ -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/lib/env.c b/usr.sbin/cron/lib/env.c
index f370601..6537262 100644
--- a/usr.sbin/cron/lib/env.c
+++ b/usr.sbin/cron/lib/env.c
@@ -16,7 +16,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char rcsid[] = "$Id: env.c,v 1.1.1.1 1994/08/27 13:43:02 jkh Exp $";
+static char rcsid[] = "$Id: env.c,v 1.2 1996/12/16 18:21:00 pst 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);
}
@@ -154,6 +176,8 @@ load_env(envstr, f)
}
}
+ if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1)
+ return (FALSE);
(void) sprintf(envstr, "%s=%s", name, val);
Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr))
return (TRUE);
OpenPOWER on IntegriCloud