diff options
author | Aaron Campbell <aaron@cvs.openbsd.org> | 1999-04-29 12:59:04 +0000 |
---|---|---|
committer | Aaron Campbell <aaron@cvs.openbsd.org> | 1999-04-29 12:59:04 +0000 |
commit | 6aa8a368c005cbf7ae2126528cb049144b082739 (patch) | |
tree | 8666a7314d8a1ab1e20d4d7283f955ccd557ab1d /bin | |
parent | d80ec05eeebd4d70c20bc76bbe6068b89532da46 (diff) |
always check return value of strdup()
Diffstat (limited to 'bin')
-rw-r--r-- | bin/pax/options.c | 12 | ||||
-rw-r--r-- | bin/pax/tables.c | 15 |
2 files changed, 19 insertions, 8 deletions
diff --git a/bin/pax/options.c b/bin/pax/options.c index 471515be843..d06eb3feab1 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.35 1998/12/07 23:45:46 deraadt Exp $ */ +/* $OpenBSD: options.c,v 1.36 1999/04/29 12:59:03 aaron Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.35 1998/12/07 23:45:46 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.36 1999/04/29 12:59:03 aaron Exp $"; #endif #endif /* not lint */ @@ -926,7 +926,7 @@ cpio_options(argc, argv) { register int c, i; size_t len; - char *str; + char *p, *str; FSUB tmp; FILE *fp; @@ -1164,7 +1164,11 @@ cpio_options(argc, argv) maxflt = 0; while ((str = fgetln(stdin, &len)) != NULL) { str[len - 1] = '\0'; - ftree_add(strdup(str), NULL); + if ((p = strdup(str)) == NULL) { + paxwarn(0, "Out of memory."); + exit(1); + } + ftree_add(p, NULL); } break; default: diff --git a/bin/pax/tables.c b/bin/pax/tables.c index 1f36fb4f28e..6f9a1d8484b 100644 --- a/bin/pax/tables.c +++ b/bin/pax/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.10 1998/07/03 06:01:20 deraadt Exp $ */ +/* $OpenBSD: tables.c,v 1.11 1999/04/29 12:59:03 aaron Exp $ */ /* $NetBSD: tables.c,v 1.4 1995/03/21 09:07:45 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: tables.c,v 1.10 1998/07/03 06:01:20 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: tables.c,v 1.11 1999/04/29 12:59:03 aaron Exp $"; #endif #endif /* not lint */ @@ -377,7 +377,11 @@ ftime_start() * get random name and create temporary scratch file, unlink name * so it will get removed on exit */ - pt = strdup("/tmp/paxXXXXXXXXXX"); + if ((pt = strdup("/tmp/paxXXXXXXXXXX")) == NULL) { + paxwarn(1, "Cannot allocate memory for temporary file name"); + (void)free((char *)ftab); + return(-1); + } if ((ffd = mkstemp(pt)) < 0) { syswarn(1, errno, "Unable to create temporary file: %s", pt); free(pt); @@ -1222,7 +1226,10 @@ dir_start() /* * unlink the file so it goes away at termination by itself */ - pt = strdup("/tmp/paxXXXXXXXXXX"); + if ((pt = strdup("/tmp/paxXXXXXXXXXX")) == NULL) { + paxwarn(1, "Cannot allocate memory for temporary filename"); + return(-1); + } if ((dirfd = mkstemp(pt)) >= 0) { (void)unlink(pt); free(pt); |