SRAT: Don't overflow domain_pxm table

If we reached MAXMEMDOM, we would previously try to insert an additional
element and only detect overflow after causing (probably trivial) memory
overflow.  Instead, detect the ndomain > MAXMEMDOM case before we write past
the end.

Reported by:	Coverity
CID:		1354783
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Conrad Meyer 2016-04-20 01:10:07 +00:00
parent fb4e4bd7f9
commit 3765b80993

View File

@ -355,17 +355,18 @@ renumber_domains(void)
if (j < ndomain && domain_pxm[j] == mem_info[i].domain)
continue;
if (ndomain >= MAXMEMDOM) {
ndomain = 1;
printf("SRAT: Too many memory domains\n");
return (EFBIG);
}
/* Insert the new domain at slot 'j'. */
slot = j;
for (j = ndomain; j > slot; j--)
domain_pxm[j] = domain_pxm[j - 1];
domain_pxm[slot] = mem_info[i].domain;
ndomain++;
if (ndomain > MAXMEMDOM) {
ndomain = 1;
printf("SRAT: Too many memory domains\n");
return (EFBIG);
}
}
/* Renumber each domain to its index in the sorted 'domain_pxm' list. */