diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2010-01-17 20:36:22 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2010-01-17 20:36:22 +0000 |
commit | 233f8a77d6f586d24e1bb0d0caa895631000c112 (patch) | |
tree | b03e3f623098daff4dd7b10eb372568c24919f01 | |
parent | dbc692771d6400f4bf70c1520ecb1092c2c51129 (diff) |
Backport bug fix from upstream.
Bug found by sthen@
ok sthen@ ian@
-rw-r--r-- | usr.bin/file/softmagic.c | 15 |
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 */ |