svn commit: r343959 - head/usr.bin/top
Dimitry Andric
dim at FreeBSD.org
Sun Feb 10 13:44:38 UTC 2019
Author: dim
Date: Sun Feb 10 13:44:36 2019
New Revision: 343959
URL: https://svnweb.freebsd.org/changeset/base/343959
Log:
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
Modified:
head/usr.bin/top/display.c
Modified: head/usr.bin/top/display.c
==============================================================================
--- head/usr.bin/top/display.c Sun Feb 10 13:34:21 2019 (r343958)
+++ head/usr.bin/top/display.c Sun Feb 10 13:44:36 2019 (r343959)
@@ -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
{
More information about the svn-src-head
mailing list