mm/gran: reject pools with too many granules

struct gran_s and struct graninfo_s store granule counts in uint16_t.
Reject pools whose computed granule count exceeds UINT16_MAX,
instead of truncating the count and creating an invalid handle.

Signed-off-by: shichunma <shichunma@bestechnic.com>
This commit is contained in:
shichunma 2026-06-16 15:44:45 +08:00 committed by Alan C. Assis
parent d8a7dee73e
commit a74d8d5d02

View file

@ -124,6 +124,14 @@ GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize,
alignedsize = (heapend - alignedstart) & ~mask;
ngranules = alignedsize >> log2gran;
/* Reject oversized pools. */
DEBUGASSERT(ngranules > 0 && ngranules <= UINT16_MAX);
if (ngranules == 0 || ngranules > UINT16_MAX)
{
return NULL;
}
/* Allocate the information structure with a granule table of the
* correct size.
*/