Skip to content

[sanitizer_common] Fix potential null dereference in dlopen interceptor #74645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

thurstond
Copy link
Contributor

The test_only_replace_dlopen_main_program flag
(introduced in 0be4c6b)
will cause internal_strcmp to dereference NULL if DlAddrSelfFName()
returns NULL (which happens in very rare cases). This patch adds a
null pointer check.

The test_only_replace_dlopen_main_program flag
(introduced in llvm@0be4c6b)
will cause internal_strcmp to dereference NULL if DlAddrSelfFName()
returns NULL (which happens in very rare cases). This patch adds a
null pointer check.
@llvmbot
Copy link
Member

llvmbot commented Dec 6, 2023

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

Author: Thurston Dang (thurstond)

Changes

The test_only_replace_dlopen_main_program flag
(introduced in 0be4c6b)
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 --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",

@thurstond thurstond merged commit 3d11728 into llvm:main Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants