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
This commit is contained in:
parent
2f301637c8
commit
7362ea6db0
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user