master hovercats/oakiss / pkg / strace / patch / 0008-Avoid-index-ranges.patch
 1From 0663a21f8a5d9d9ffd8e79bfb0c326365d98e384 Mon Sep 17 00:00:00 2001
 2From: Michael Forney <mforney@mforney.org>
 3Date: Thu, 30 Jan 2020 22:32:50 -0800
 4Subject: [PATCH] Avoid index ranges
 5
 6The change in print_mac.c is not functionally the same, but we
 7ignore this for now.
 8---
 9 src/print_mac.c | 4 +---
10 src/util.c      | 8 ++++----
11 2 files changed, 5 insertions(+), 7 deletions(-)
12
13diff --git a/src/print_mac.c b/src/print_mac.c
14index cad1013a8..73d7bbe28 100644
15--- a/src/print_mac.c
16+++ b/src/print_mac.c
17@@ -17,8 +17,6 @@
18 DIAG_PUSH_IGNORE_OVERRIDE_INIT
19 
20 static uint8_t hwaddr_sizes[] = {
21-	[0 ... ARPHRD_VSOCKMON] = 255,
22-
23 	[ARPHRD_NETROM]     =  7 /* AX25_ADDR_LEN */,
24 	[ARPHRD_ETHER]      =  6 /* ETH_ALEN */,
25 	/* ARPHRD_EETHER - no actual devices in Linux */
26@@ -129,7 +127,7 @@ print_mac_addr(const char *prefix, const uint8_t addr[], size_t size)
27 static const char *
28 sprint_hwaddr(const uint8_t hwaddr[], size_t size, uint32_t devtype)
29 {
30-	uint8_t sz = (devtype < ARRAY_SIZE(hwaddr_sizes))
31+	uint8_t sz = (devtype < ARRAY_SIZE(hwaddr_sizes) && hwaddr_sizes[devtype])
32 			? hwaddr_sizes[devtype] : 255;
33 
34 	return sprint_mac_addr(hwaddr, MIN(size, sz));
35diff --git a/src/util.c b/src/util.c
36index eb5896eec..e92a25264 100644
37--- a/src/util.c
38+++ b/src/util.c
39@@ -1660,16 +1660,16 @@ dumpstr(struct tcb *const tcp, const kernel_ulong_t addr,
40 		? 1 + ilog2_klong(len - 1) / HEX_BIT : DUMPSTR_OFFS_MIN_CHARS;
41 	kernel_ulong_t i = 0;
42 	const unsigned char *src;
43+	char outbuf[DUMPSTR_WIDTH_CHARS + 1];
44+
45+	memset(outbuf, ' ', DUMPSTR_WIDTH_CHARS);
46+	outbuf[DUMPSTR_WIDTH_CHARS] = '\0';
47 
48 	while (i < len) {
49 		/*
50 		 * It is important to overwrite all the byte values, as we
51 		 * re-use the buffer in order to avoid its re-initialisation.
52 		 */
53-		static char outbuf[] = {
54-			[0 ... DUMPSTR_WIDTH_CHARS - 1] = ' ',
55-			'\0'
56-		};
57 		char *dst = outbuf;
58 
59 		/* Fetching data from tracee.  */
60-- 
612.44.0
62