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

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 11:08:08 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Thurston Dang (thurstond)

<details>
<summary>Changes</summary>

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.


---
Full diff: https://github.com/llvm/llvm-project/pull/74645.diff


1 Files Affected:

- (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc (+1-1) 


``````````diff
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",

``````````

</details>


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


More information about the llvm-commits mailing list