summaryrefslogtreecommitdiffstats
path: root/usr.bin/file/apprentice.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1998-08-19 17:20:01 +0000
committerderaadt <deraadt@openbsd.org>1998-08-19 17:20:01 +0000
commitce6bb56d36eca0e4a210f4b48c1a6d6fe9f2d101 (patch)
treebd1f7069e483d5e6e8a3ef0d257892ac4a3192ad /usr.bin/file/apprentice.c
parentbuf oflows; reported by felix@schlund.de but fixed by me because he did not send in a patch (diff)
downloadwireguard-openbsd-ce6bb56d36eca0e4a210f4b48c1a6d6fe9f2d101.tar.xz
wireguard-openbsd-ce6bb56d36eca0e4a210f4b48c1a6d6fe9f2d101.zip
realloc fix
Diffstat (limited to 'usr.bin/file/apprentice.c')
-rw-r--r--usr.bin/file/apprentice.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/file/apprentice.c b/usr.bin/file/apprentice.c
index 6ec2908cefd..af1a424e063 100644
--- a/usr.bin/file/apprentice.c
+++ b/usr.bin/file/apprentice.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: apprentice.c,v 1.5 1998/07/10 15:05:13 mickey Exp $ */
+/* $OpenBSD: apprentice.c,v 1.6 1998/08/19 17:20:01 deraadt Exp $ */
/*
* apprentice - make one pass through /etc/magic, learning its secrets.
@@ -36,7 +36,7 @@
#include "file.h"
#ifndef lint
-static char *moduleid = "$OpenBSD: apprentice.c,v 1.5 1998/07/10 15:05:13 mickey Exp $";
+static char *moduleid = "$OpenBSD: apprentice.c,v 1.6 1998/08/19 17:20:01 deraadt Exp $";
#endif /* lint */
#define EATAB {while (isascii((unsigned char) *l) && \
@@ -183,14 +183,19 @@ int *ndx, check;
#define ALLOC_INCR 20
if (nd+1 >= maxmagic){
+ struct magic *mtmp;
+
maxmagic += ALLOC_INCR;
- if ((magic = (struct magic *) realloc(magic,
+ if ((mtmp = (struct magic *) realloc(magic,
sizeof(struct magic) *
maxmagic)) == NULL) {
warn("malloc");
- if (check)
+ if (check) {
+ if (magic)
+ free(magic);
+ magic = mtmp;
return -1;
- else
+ } else
exit(1);
}
memset(&magic[*ndx], 0, sizeof(struct magic) * ALLOC_INCR);