diff options
author | 2010-01-17 20:36:21 +0000 | |
---|---|---|
committer | 2010-01-17 20:36:21 +0000 | |
commit | 1e172b54231c336802d56182478030bb3e222c93 (patch) | |
tree | bdedb901c8665252dfe15f9de24fffc1835615ed | |
parent | Remove dead assignment and newly created unused variable. (diff) | |
download | wireguard-openbsd-1e172b54231c336802d56182478030bb3e222c93.tar.xz wireguard-openbsd-1e172b54231c336802d56182478030bb3e222c93.zip |
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 */ |