This is an automated email from the ASF dual-hosted git repository.

xiaoxiang 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 045b9ffd54 mempool:fix bug read out of bounds when realloc
045b9ffd54 is described below

commit 045b9ffd5480aa2e72ffa1c7e6464cf90acf3ff0
Author: anjiahao <[email protected]>
AuthorDate: Fri May 19 19:28:14 2023 +0800

    mempool:fix bug read out of bounds when realloc
    
    fix kasan report
    
    Signed-off-by: anjiahao <[email protected]>
---
 mm/mm_heap/mm_realloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c
index 859ab692db..0fab7c3b07 100644
--- a/mm/mm_heap/mm_realloc.c
+++ b/mm/mm_heap/mm_realloc.c
@@ -93,7 +93,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void 
*oldmem,
       newmem = mm_malloc(heap, size);
       if (newmem != NULL)
         {
-          memcpy(newmem, oldmem, size);
+          memcpy(newmem, oldmem, MIN(size, mm_malloc_size(heap, oldmem)));
           mm_free(heap, oldmem);
         }
 

Reply via email to