top(1): fix a buffer overflow copying states to display while they were incremented

- fix an AddressSanitizer error

Submitted by:	devnexen@gmail.com
Reviewed by:	eadler
Approved by:	gnn (mentor)
Differential Revision:	https://reviews.freebsd.org/D16183
This commit is contained in:
Daichi GOTO 2018-07-27 07:05:50 +00:00
parent 9977c7b512
commit 08092a9b8f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336756

View File

@ -420,6 +420,7 @@ i_cpustates(int *states)
int value;
const char * const *names;
const char *thisname;
int *hstates = states;
int cpu;
for (cpu = 0; cpu < num_cpus; cpu++) {
@ -453,6 +454,7 @@ for (cpu = 0; cpu < num_cpus; cpu++) {
}
/* copy over values into "last" array */
states = hstates;
memcpy(lcpustates, states, num_cpustates * sizeof(int) * num_cpus);
}
@ -462,6 +464,7 @@ u_cpustates(int *states)
int value;
const char * const *names;
const char *thisname;
int *hstates = states;
int *lp;
int *colp;
int cpu;
@ -504,6 +507,8 @@ for (cpu = 0; cpu < num_cpus; cpu++) {
colp++;
}
}
states = hstates;
}
void