[compiler-rt] [sanitizer_common] Fix potential null dereference in dlopen interceptor (PR #74645)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 11:07:38 PST 2023


https://github.com/thurstond created https://github.com/llvm/llvm-project/pull/74645

The test_only_replace_dlopen_main_program flag
(introduced in https://github.com/llvm/llvm-project/commit/0be4c6b9483594494051e8f1f67afc2b516270ca)
will cause internal_strcmp to dereference NULL if DlAddrSelfFName()
returns NULL (which happens in very rare cases). This patch adds a
null pointer check.


>From dfaedcb501c2af07d20b8838dc116ea305bfbe85 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Wed, 6 Dec 2023 19:03:22 +0000
Subject: [PATCH] [sanitizer_common] Fix potential null dereference in dlopen
 interceptor

The test_only_replace_dlopen_main_program flag
(introduced in https://github.com/llvm/llvm-project/commit/0be4c6b9483594494051e8f1f67afc2b516270ca)
will cause internal_strcmp to dereference NULL if DlAddrSelfFName()
returns NULL (which happens in very rare cases). This patch adds a
null pointer check.
---
 .../lib/sanitizer_common/sanitizer_common_interceptors.inc      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 607ecae6808b7..ba46707516971 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -6327,7 +6327,7 @@ INTERCEPTOR(void*, dlopen, const char *filename, int flag) {
       VPrintf(1, "dlopen interceptor: DladdrSelfFName: %p %s\n",
               (void *)SelfFName, SelfFName);
 
-      if (internal_strcmp(SelfFName, filename) == 0) {
+      if (SelfFName && internal_strcmp(SelfFName, filename) == 0) {
         // It's possible they copied the string from dladdr, so
         // we do a string comparison rather than pointer comparison.
         VPrintf(1, "dlopen interceptor: replacing %s because it matches %s\n",



More information about the llvm-commits mailing list