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

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


Author: Thurston Dang
Date: 2023-12-06T12:11:48-08:00
New Revision: 3d1172813fc640514c6cb421394c34f4b42cb634

URL: https://github.com/llvm/llvm-project/commit/3d1172813fc640514c6cb421394c34f4b42cb634
DIFF: https://github.com/llvm/llvm-project/commit/3d1172813fc640514c6cb421394c34f4b42cb634.diff

LOG: [sanitizer_common] Fix potential null dereference in dlopen interceptor (#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.

Co-authored-by: Thurston Dang <thurston at google.com>

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Removed: 
    


################################################################################
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