]> granicus.if.org Git - procps-ng/commitdiff
top: prevent buffer overruns in 'inspection_utility()'
authorJim Warner <james.warner@comcast.net>
Sun, 3 Jun 2018 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sat, 9 Jun 2018 11:35:20 +0000 (21:35 +1000)
For our master branch, a Qualys patch referenced below
was reverted as being unwarranted. That original patch
was not applied in this branch so there was no revert.

However, there was 1 specific problem their patch had,
in fact, prevented. Thus, this patch now addresses it.

Reference(s):
. original qualys patch
0109-top-Protect-scat-from-buffer-overflows.patch

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 18f2a3b1f4ac52080082af6ca8b5ebab2ee1ec3b..91493bc1766e3ef34731e5c398802f7c510b133b 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -2990,8 +2990,8 @@ static void inspection_utility (int pid) {
       Inspect.tab[sel].caps = "~4"; dst[0] = '\0'; \
       for (i = 0; i < Inspect.total; i++) { char _s[SMLBUFSIZ]; \
          snprintf(_s, sizeof(_s), " %s %s", Inspect.tab[i].name, Inspect.tab[i].caps); \
-         strcat(dst, _s); } }
-   char sels[MEDBUFSIZ];
+         strncat(dst, _s, (sizeof(dst) - 1) - strlen(dst)); } }
+   char sels[SCREENMAX];
    static int sel;
    int i, key;
    struct pids_stack *p;