Skip to content

Commit 98a20cd

Browse files
procrank: fix bounds check to prevent heap overflow
Bug: 30774296 Change-Id: I44005caaa3cc17fe829f375a4cfeb5a464c97fbe
1 parent 17985b2 commit 98a20cd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: libpagemap/pm_memusage.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ void pm_memusage_pswap_add_offset(pm_memusage_t *mu, unsigned int offset) {
8989
if (mu->p_swap == NULL)
9090
return;
9191

92-
if (offset > mu->p_swap->array_size) {
92+
if (offset >= mu->p_swap->array_size) {
9393
fprintf(stderr, "SWAP offset %d is out of swap bounds.\n", offset);
9494
return;
95+
}
96+
97+
if (mu->p_swap->offset_array[offset] == USHRT_MAX) {
98+
fprintf(stderr, "SWAP offset %d ref. count if overflowing ushort type.\n", offset);
9599
} else {
96-
if (mu->p_swap->offset_array[offset] == USHRT_MAX) {
97-
fprintf(stderr, "SWAP offset %d ref. count if overflowing ushort type.\n", offset);
98-
} else {
99-
mu->p_swap->offset_array[offset]++;
100-
}
100+
mu->p_swap->offset_array[offset]++;
101101
}
102102

103103
soff = malloc(sizeof(pm_swap_offset_t));

0 commit comments

Comments
 (0)