[PATCH] elfint.c: Fix NULL pointer dereference issue in process_file function

2024-10-23 Thread ant . v . moryakov
From: AntonMoryakov 

fix: fixed null pointer inference error in process_file function

Fixed a bug that could cause the program to crash when processing files without 
a suffix.
Added a NULL check for the suffix pointer before calling stpcpy().
---
 src/elflint.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/elflint.c b/src/elflint.c
index cdc6108d..14346045 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -257,7 +257,12 @@ process_file (int fd, Elf *elf, const char *prefix, const 
char *suffix,
  {
cp = mempcpy (cp, prefix, prefix_len);
*cp++ = '(';
-   strcpy (stpcpy (new_suffix, suffix), ")");
+   if(suffix != NULL){
+   strcpy (stpcpy (new_suffix, suffix), ")");
+   }
+   else{
+   new_suffix[0] = '\0';
+   }
  }
else
  new_suffix[0] = '\0';
-- 
2.34.1



[PATCH] dwarf_ranges.c: Prevent null pointer dereference in dwarf_ranges

2024-10-23 Thread ant . v . moryakov
From: AntonMoryakov 

Fix a bug that caused a null pointer dereference in the `dwarf_ranges` function.
Added a check for NULL before dereferencing the pointer `d` to prevent potential
segmentation faults.
---
 libdw/dwarf_ranges.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libdw/dwarf_ranges.c b/libdw/dwarf_ranges.c
index b853e4b9..a4a04761 100644
--- a/libdw/dwarf_ranges.c
+++ b/libdw/dwarf_ranges.c
@@ -532,9 +532,10 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr 
*basep,
 secidx, offset, 1))
return -1;
 }
-
-  readp = d->d_buf + offset;
-  readendp = d->d_buf + d->d_size;
+  if(d != NULL){
+   readp = d->d_buf + offset;
+   readendp = d->d_buf + d->d_size;
+  }
 
   Dwarf_Addr begin;
   Dwarf_Addr end;
-- 
2.34.1



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

2024-10-23 Thread ant . v . moryakov
From: AntonMoryakov 

- 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



[PATCH] objdump.c: potential NULL pointer dereference in handle_ar

2024-10-23 Thread ant . v . moryakov
From: AntonMoryakov 

- Added a check to ensure `arhdr` is not NULL before using it in `strcmp` to 
avoid segmentation fault.
- This resolves the issue where the pointer returned from `elf_getarhdr` may be 
NULL and causes a crash when dereferenced.
---
 src/objdump.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/objdump.c b/src/objdump.c
index 1b38da23..33b6fec5 100644
--- a/src/objdump.c
+++ b/src/objdump.c
@@ -313,7 +313,8 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char 
*fname,
   Elf_Arhdr *arhdr = elf_getarhdr (subelf);
 
   /* Skip over the index entries.  */
-  if (strcmp (arhdr->ar_name, "/") != 0
+  if (arhdr != NULL
+&& strcmp (arhdr->ar_name, "/") != 0
  && strcmp (arhdr->ar_name, "//") != 0)
{
  if (elf_kind (subelf) == ELF_K_ELF)
-- 
2.34.1