[PATCH] dwfl_segment_report_module.c: Fix potential NULL pointer dereference in handle_file_note

ant.v.moryakov@gmail.com ant.v.moryakov@gmail.com
Wed Oct 23 11:08:09 GMT 2024


From: AntonMoryakov <ant.v.moryakov@gmail.com>

- Added a check to ensure `retval` is not NULL before using it in `strcmp` to prevent a segmentation fault.
- This resolves the issue where `retval` could be NULL when passed to `strcmp`, which could cause a crash.
---
 libdwfl/dwfl_segment_report_module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 32f44af8..d2512cb3 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -205,7 +205,7 @@ handle_file_note (GElf_Addr module_start, GElf_Addr module_end,
 	return NULL;
       if (mix == firstix)
 	retval = fptr;
-      if (firstix < mix && mix <= lastix && strcmp (fptr, retval) != 0)
+      if (retval != NULL && firstix < mix && mix <= lastix && strcmp (fptr, retval) != 0)
 	return NULL;
       fptr = fnext + 1;
     }
-- 
2.34.1



More information about the Elfutils-devel mailing list