[elf] Fix possible null-pointer dereference.

Message ID 20220331154411.442438-1-d.chestnyh@omp.ru
State New
Headers
Series [elf] Fix possible null-pointer dereference. |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Dmitry Chestnyh March 31, 2022, 3:44 p.m. UTC
  This issue was found by SVACE static analyzer.
Dereference can appear at line 203 and there are no
obvious checks of `map->l_name` ptr value.
And seems that we can't be sure that this pointer
isn't NULL.
---
 elf/sotruss-lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/elf/sotruss-lib.c b/elf/sotruss-lib.c
index a5edd438f9..030c818a3e 100644
--- a/elf/sotruss-lib.c
+++ b/elf/sotruss-lib.c
@@ -200,7 +200,7 @@  la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t *cookie)
      from or that list must be empty.  In the latter case we trace
      only calls from the main binary.  */
   if (fromlist == NULL)
-    result |= map->l_name[0] == '\0' ? LA_FLG_BINDFROM : 0;
+    result |= (map->l_name && map->l_name[0] == '\0') ? LA_FLG_BINDFROM : 0;
   else
     result |= (match_file (fromlist, full_name, full_name_len,
 			   LA_FLG_BINDFROM)