master hovercats/oakiss / pkg / strace / patch / 0005-Avoid-unnecessary-VLAs.patch
  1From 8c03823959bcb53e16a6555fcc880fe4560cb79f Mon Sep 17 00:00:00 2001
  2From: Michael Forney <mforney@mforney.org>
  3Date: Sun, 7 Jul 2019 21:58:46 -0700
  4Subject: [PATCH] Avoid unnecessary VLAs
  5
  6---
  7 src/count.c       | 2 +-
  8 src/nlattr.c      | 2 +-
  9 src/socketutils.c | 4 ++--
 10 src/syscall.c     | 2 +-
 11 src/util.c        | 5 ++---
 12 5 files changed, 7 insertions(+), 8 deletions(-)
 13
 14diff --git a/src/count.c b/src/count.c
 15index 2494a44d6..704e3a8d5 100644
 16--- a/src/count.c
 17+++ b/src/count.c
 18@@ -414,7 +414,7 @@ call_summary_pers(FILE *outf)
 19 		fprintf(outf, column_fmts[i], (val_), cwidths[c]); \
 20 		break
 21 
 22-	const char *column_fmts[last_column + 1];
 23+	const char *column_fmts[ARRAY_SIZE(columns)];
 24 	for (size_t i = 0; i <= last_column; ++i) {
 25 		const size_t c = columns[i];
 26 
 27diff --git a/src/nlattr.c b/src/nlattr.c
 28index 9944afb8c..1252510a5 100644
 29--- a/src/nlattr.c
 30+++ b/src/nlattr.c
 31@@ -310,7 +310,7 @@ DECL_NLA(hwaddr)
 32 	if (len > MAX_ADDR_LEN)
 33 		return false;
 34 
 35-	uint8_t buf[len];
 36+	uint8_t buf[MAX_ADDR_LEN];
 37 	const uintptr_t arphrd = (uintptr_t) opaque_data;
 38 
 39 	if (!umoven_or_printaddr(tcp, addr, len, buf)) {
 40diff --git a/src/socketutils.c b/src/socketutils.c
 41index d3a3b9283..e0079456f 100644
 42--- a/src/socketutils.c
 43+++ b/src/socketutils.c
 44@@ -133,7 +133,7 @@ inet_parse_response(const void *const data, const int data_len,
 45 			return -1;
 46 	}
 47 
 48-	char src_buf[text_size];
 49+	char src_buf[INET6_ADDRSTRLEN];
 50 	char *details;
 51 
 52 	/* open/closing brackets for IPv6 addresses */
 53@@ -146,7 +146,7 @@ inet_parse_response(const void *const data, const int data_len,
 54 
 55 	if (diag_msg->id.idiag_dport ||
 56 	    memcmp(zero_addr, diag_msg->id.idiag_dst, addr_size)) {
 57-		char dst_buf[text_size];
 58+		char dst_buf[INET6_ADDRSTRLEN];
 59 
 60 		if (!inet_ntop(diag_msg->idiag_family, diag_msg->id.idiag_dst,
 61 			       dst_buf, text_size))
 62diff --git a/src/syscall.c b/src/syscall.c
 63index 1f4d86dc1..84d448253 100644
 64--- a/src/syscall.c
 65+++ b/src/syscall.c
 66@@ -287,7 +287,7 @@ decode_socket_subcall(struct tcb *tcp)
 67 
 68 	const kernel_ulong_t scno = SYS_socket_subcall + call;
 69 	const unsigned int nargs = sysent[scno].nargs;
 70-	uint64_t buf[nargs];
 71+	uint64_t buf[MAX_ARGS];
 72 
 73 	if (umoven(tcp, tcp->u_arg[1], nargs * current_wordsize, buf) < 0)
 74 		return;
 75diff --git a/src/util.c b/src/util.c
 76index a88dd008d..eb5896eec 100644
 77--- a/src/util.c
 78+++ b/src/util.c
 79@@ -569,8 +569,7 @@ enum sock_proto
 80 getfdproto(struct tcb *tcp, int fd)
 81 {
 82 #ifdef HAVE_SYS_XATTR_H
 83-	size_t bufsize = 256;
 84-	char buf[bufsize];
 85+	char buf[256];
 86 	ssize_t r;
 87 	char path[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];
 88 
 89@@ -578,7 +577,7 @@ getfdproto(struct tcb *tcp, int fd)
 90 		return SOCK_PROTO_UNKNOWN;
 91 
 92 	xsprintf(path, "/proc/%u/fd/%u", get_proc_pid(tcp->pid), fd);
 93-	r = getxattr(path, "system.sockprotoname", buf, bufsize - 1);
 94+	r = getxattr(path, "system.sockprotoname", buf, sizeof(buf) - 1);
 95 	if (r <= 0)
 96 		return SOCK_PROTO_UNKNOWN;
 97 	else {
 98-- 
 992.44.0
100