lnstat: fix buffer overflow in header output

Running lnstat will cause core dump from reading past end of array.

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 <jiangheng12@huawei.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
[200~jiangheng 2021-11-17 13:41:10 -08:00 committed by Stephen Hemminger
parent 0e94972590
commit be31c26484
1 changed files with 2 additions and 1 deletions

View File

@ -210,8 +210,9 @@ 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] = ' ';