summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron/lib/env.c
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/env.c
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/env.c')
-rw-r--r--usr.sbin/cron/lib/env.c34
1 files changed, 29 insertions, 5 deletions
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