This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new a74d8d5d02a mm/gran: reject pools with too many granules
a74d8d5d02a is described below
commit a74d8d5d02aee2563346edf4f95f7fda037b241e
Author: shichunma <[email protected]>
AuthorDate: Tue Jun 16 15:44:45 2026 +0800
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 <[email protected]>
---
mm/mm_gran/mm_graninit.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mm/mm_gran/mm_graninit.c b/mm/mm_gran/mm_graninit.c
index 0ae0e4cf8b5..ade271c2c46 100644
--- a/mm/mm_gran/mm_graninit.c
+++ b/mm/mm_gran/mm_graninit.c
@@ -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.
*/