0008-Avoid-unnecessary-VLAs.patch (2971B)
1 From a98e58cc36d6df5935dbedd9e1c2947262b8b67c Mon Sep 17 00:00:00 2001 2 From: Michael Forney <mforney@mforney.org> 3 Date: Sun, 7 Jul 2019 21:58:46 -0700 4 Subject: [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 14 diff --git a/src/count.c b/src/count.c 15 index e4f362787..ad203748b 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 27 diff --git a/src/nlattr.c b/src/nlattr.c 28 index 1fb394d7c..6f2d54979 100644 29 --- a/src/nlattr.c 30 +++ b/src/nlattr.c 31 @@ -357,7 +357,7 @@ decode_nla_hwaddr(struct tcb *const tcp, 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)) { 40 diff --git a/src/socketutils.c b/src/socketutils.c 41 index 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)) 62 diff --git a/src/syscall.c b/src/syscall.c 63 index c636ba37c..687d08bc0 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; 75 diff --git a/src/util.c b/src/util.c 76 index a63d80678..a3bea5b76 100644 77 --- a/src/util.c 78 +++ b/src/util.c 79 @@ -556,8 +556,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 @@ -565,7 +564,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 -- 99 2.37.3 100