summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-11-12 20:10:49 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-11-12 20:10:49 +0000
commit6b8bde97640c2e6d37153682191accac4ba2f773 (patch)
treea2a8399a9663626f721afc1412bdcd6e72a50d8a
parent5b3257fb70bf6ba2d536cc10ac999aa555da8cae (diff)
Do realloc() the paranoid way, at the very least to once again educate
people about the potential for memory leaks when realloc is use sloppily ok miod
-rw-r--r--bin/pax/options.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/bin/pax/options.c b/bin/pax/options.c
index 7a5589ab6f3..ce46a493cc4 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.71 2009/10/27 23:59:22 deraadt Exp $ */
+/* $OpenBSD: options.c,v 1.72 2009/11/12 20:10:48 deraadt Exp $ */
/* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
/*-
@@ -761,14 +761,20 @@ tar_options(int argc, char **argv)
break;
case 'I':
if (++nincfiles > incfiles_max) {
- incfiles_max = nincfiles + 3;
- incfiles = realloc(incfiles,
- sizeof(*incfiles) * incfiles_max);
- if (incfiles == NULL) {
+ size_t n = nincfiles + 3;
+ struct incfile *p;
+
+ p = realloc(incfiles,
+ sizeof(*incfiles) * n);
+ if (p == NULL) {
+ free(incfiles);
+ incfiles = NULL;
paxwarn(0, "Unable to allocate space "
"for option list");
exit(1);
}
+ incfiles = p;
+ incfiles_max = n;
}
incfiles[nincfiles - 1].file = optarg;
incfiles[nincfiles - 1].dir = chdname;