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-07-03 10:32:15 +08:00
committed by Xiang Xiao
parent 0f4f53f3ea
commit aeed361f4e
+8
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.
*/