1From 542380a13f178d97851751b57054a6b5be555d1c Mon Sep 17 00:00:00 2001
2From: Jens Rehsack <sno@netbsd.org>
3Date: Thu, 13 Aug 2020 16:16:44 +0200
4Subject: [PATCH 2/2] test/test_x509.c: fix potential overflow issue
5
6Instead of doing a memcpy() which does static overflow checking, use
7snprintf() for string copying which does the check dynamically.
8
9Fixes:
10| In file included from .../recipe-sysroot/usr/include/string.h:519,
11|                  from test/test_x509.c:27:
12| In function 'memcpy',
13|     inlined from 'parse_keyvalue' at test/test_x509.c:845:2,
14|     inlined from 'process_conf_file' at test/test_x509.c:1360:7,
15|     inlined from 'main' at test/test_x509.c:2038:2:
16| .../recipe-sysroot/usr/include/bits/string_fortified.h:34:10: warning: '__builtin_memcpy' specified bound 4294967295 exceeds maximum object size 2147483647 [-Wstringop-overflow=]
17|    34 |   return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
18|       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
20Signed-off-by: Jens Rehsack <sno@netbsd.org>
21---
22Upstream-Status: Pending
23
24 test/test_x509.c | 3 +--
25 1 file changed, 1 insertion(+), 2 deletions(-)
26
27diff --git a/test/test_x509.c b/test/test_x509.c
28index 2c61cf5..76f6ab9 100644
29--- a/test/test_x509.c
30+++ b/test/test_x509.c
31@@ -842,8 +842,7 @@ parse_keyvalue(HT *d)
32 		return -1;
33 	}
34 	name = xmalloc(u + 1);
35-	memcpy(name, buf, u);
36-	name[u] = 0;
37+	snprintf(name, u, "%s", buf);
38 	if (HT_get(d, name) != NULL) {
39 		xfree(name);
40 		return -1;
41--
422.17.1
43
44