summaryrefslogtreecommitdiff
path: root/usr.bin/file
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2010-01-17 20:36:22 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2010-01-17 20:36:22 +0000
commit233f8a77d6f586d24e1bb0d0caa895631000c112 (patch)
treeb03e3f623098daff4dd7b10eb372568c24919f01 /usr.bin/file
parentdbc692771d6400f4bf70c1520ecb1092c2c51129 (diff)
Backport bug fix from upstream.
Bug found by sthen@ ok sthen@ ian@
Diffstat (limited to 'usr.bin/file')
-rw-r--r--usr.bin/file/softmagic.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/usr.bin/file/softmagic.c b/usr.bin/file/softmagic.c
index cde4a21f9e5..cc496d17680 100644
--- a/usr.bin/file/softmagic.c
+++ b/usr.bin/file/softmagic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softmagic.c,v 1.15 2009/10/27 23:59:38 deraadt Exp $ */
+/* $OpenBSD: softmagic.c,v 1.16 2010/01/17 20:36:21 chl Exp $ */
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
@@ -307,14 +307,13 @@ strndup(const char *str, size_t n)
size_t len;
char *copy;
- len = strlen(str);
- if (len > n)
- len = n;
- if (!(copy = malloc(len + 1)))
- return (NULL);
- (void) memcpy(copy, str, len + 1);
+ for (len = 0; len < n && str[len]; len++)
+ continue;
+ if ((copy = malloc(len + 1)) == NULL)
+ return NULL;
+ (void)memcpy(copy, str, len);
copy[len] = '\0';
- return (copy);
+ return copy;
}
#endif /* HAVE_STRNDUP */