summaryrefslogtreecommitdiff
path: root/usr.bin/make/make_malloc.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-08-12 03:27:29 +0000
committerrillig <rillig@NetBSD.org>2020-08-12 03:27:29 +0000
commit9d79a9921a9a5bef808ea1f96fce78775118bc79 (patch)
tree4865b7795a6b155d9d391032e72629009584b017 /usr.bin/make/make_malloc.c
parente6c629b9e69f2cec3798bdd0d36318eb17658a66 (diff)
make(1): in bmake_strndup, only scan the relevant part of the string
Just in case the given str is not really a string. The POSIX 2018 documentation on strndup does not specify as clearly as possible whether s has to be a string or whether raw memory is acceptable as well. It only indirectly calls the s parameter of strndup a string.
Diffstat (limited to 'usr.bin/make/make_malloc.c')
-rw-r--r--usr.bin/make/make_malloc.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/usr.bin/make/make_malloc.c b/usr.bin/make/make_malloc.c
index 7e2f75ff85e..17c7f63a5b5 100644
--- a/usr.bin/make/make_malloc.c
+++ b/usr.bin/make/make_malloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: make_malloc.c,v 1.12 2020/07/03 08:02:55 rillig Exp $ */
+/* $NetBSD: make_malloc.c,v 1.13 2020/08/12 03:27:29 rillig Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
#ifdef MAKE_NATIVE
#include <sys/cdefs.h>
-__RCSID("$NetBSD: make_malloc.c,v 1.12 2020/07/03 08:02:55 rillig Exp $");
+__RCSID("$NetBSD: make_malloc.c,v 1.13 2020/08/12 03:27:29 rillig Exp $");
#endif
#include <stdio.h>
@@ -95,9 +95,9 @@ bmake_strndup(const char *str, size_t max_len)
if (str == NULL)
return NULL;
- len = strlen(str);
- if (len > max_len)
- len = max_len;
+ for (len = 0; len < max_len; len++)
+ if (str[len] == '\0')
+ break;
p = bmake_malloc(len + 1);
memcpy(p, str, len);
p[len] = '\0';