aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-02-10 13:44:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-02-10 13:44:36 +0000
commit7362ea6db0737a6f2862faccb11650662a43ed90 (patch)
treedfa73f0ef519e56388d1f2d38cc462871959ef52 /usr.bin/top
parent2f301637c8b662c3aa9e698db39095d0a62729de (diff)
downloadsrc-7362ea6db0737a6f2862faccb11650662a43ed90.tar.gz
src-7362ea6db0737a6f2862faccb11650662a43ed90.zip
Fix the first couple of AddressSanitizer violations in usr.bin/top.
Avoid setting zero bytes beyond the length of the 'thisline' parameters in i_process() and u_process(), and don't attempt to memset a negative number of bytes. MFC after: 1 week
Notes
Notes: svn path=/head/; revision=343959
Diffstat (limited to 'usr.bin/top')
-rw-r--r--usr.bin/top/display.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/usr.bin/top/display.c b/usr.bin/top/display.c
index 03277ea86cf2..b17be6e83569 100644
--- a/usr.bin/top/display.c
+++ b/usr.bin/top/display.c
@@ -829,7 +829,11 @@ i_process(int line, char *thisline)
}
/* truncate the line to conform to our current screen width */
- thisline[screen_width] = '\0';
+ int len = strlen(thisline);
+ if (screen_width < len)
+ {
+ thisline[screen_width] = '\0';
+ }
/* write the line out */
fputs(thisline, stdout);
@@ -839,7 +843,10 @@ i_process(int line, char *thisline)
p = stpcpy(base, thisline);
/* zero fill the rest of it */
- memset(p, 0, screen_width - (p - base));
+ if (p - base < screen_width)
+ {
+ memset(p, 0, screen_width - (p - base));
+ }
}
void
@@ -853,7 +860,11 @@ u_process(int line, char *newline)
bufferline = &screenbuf[lineindex(line)];
/* truncate the line to conform to our current screen width */
- newline[screen_width] = '\0';
+ int len = strlen(newline);
+ if (screen_width < len)
+ {
+ newline[screen_width] = '\0';
+ }
/* is line higher than we went on the last display? */
if (line >= last_hi)
@@ -878,7 +889,10 @@ u_process(int line, char *newline)
optr = stpcpy(bufferline, newline);
/* zero fill the rest of it */
- memset(optr, 0, screen_width - (optr - bufferline));
+ if (optr - bufferline < screen_width)
+ {
+ memset(optr, 0, screen_width - (optr - bufferline));
+ }
}
else
{