Skip to contentSkip to conversation

lnstat:fix buffer overflow in lnstat lnstat segfaults when called the following command: $ lnstat -w 1

PATCH jiangheng (H) 1 participant 1 message Nov 15, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From d797c268003919f6e83c1bbdccebf62805dc2581 Mon Sep 17 00:00:00 2001
From: jiangheng <[email protected]>
Date: Thu, 11 Nov 2021 18:20:26 +0800
Subject: [PATCH iproute2] lnstat:fix buffer overflow in lnstat command

segfaults when called the following command: lnstat -w 1 [root@localhost ~]# lnstat -w 1
Segmentation fault (core dumped)

The maximum value of th.num_lines is HDR_LINES(10), h should not be equal to th.num_lines, array th.hdr may be out of bounds.

Signed-off-by jiangheng <[email protected]>
---
misc/lnstat.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
misc/lnstat.c +1 -1
@@ -211,7 +211,7 @@ static struct table_hdr *build_hdr_string(struct lnstat_file *lnstat_files,
 		ofs += width+1;
 	}
 	/* fill in spaces */
-	for (h = 1; h <= th.num_lines; h++) {
+	for (h = 1; h < th.num_lines; h++) {
 		for (i = 0; i < ofs; i++) {
 			if (th.hdr[h][i] == '\0')
 				th.hdr[h][i] = ' ';

--
2.27.0