mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
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:
parent
0f4f53f3ea
commit
aeed361f4e
1 changed files with 8 additions and 0 deletions
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue