Skip to content

Commit

Permalink
libfabric/core: Fix integer overflow in ofi_get_mem_size
Browse files Browse the repository at this point in the history
Need to ensure that the multiplication of page_cnt and
page_size does not exceed the maximum value that can be
held by a size_t variable.
This modification ensures that the function checks for
overflow conditions before performing the multiplication

Signed-off-by: Juee Himalbhai Desai <[email protected]>
  • Loading branch information
Juee14Desai committed Jul 11, 2024
1 parent 0fd0515 commit 7feb442
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ size_t ofi_get_mem_size(void)
if (page_cnt <= 0 || page_size <= 0)
return 0;

if (page_cnt > SIZE_MAX / page_size)
return 0;

mem_size = (size_t) page_cnt * (size_t) page_size;
if (mem_size < page_cnt || mem_size < page_size)
return 0;
Expand Down

0 comments on commit 7feb442

Please sign in to comment.