This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch releases/13.0
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/releases/13.0 by this push:
new aeed361f4ee mm/gran: reject pools with too many granules
aeed361f4ee is described below
commit aeed361f4eeeecc6efa523b792db13a34a79b648
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.
*/