[compiler-rt] r331382 - [sanitizer] Fix Fuchsia ReadBinaryName not to crash when uninitialized

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Wed May 2 11:08:47 PDT 2018


Author: phosek
Date: Wed May  2 11:08:47 2018
New Revision: 331382

URL: http://llvm.org/viewvc/llvm-project?rev=331382&view=rev
Log:
[sanitizer] Fix Fuchsia ReadBinaryName not to crash when uninitialized

If the sanitizer runtime is loaded in a binary that doesn't really
support it, then __sanitizer_startup_hook will never have been
called to initialize StoredArgv. This case can't be supported, but
its failure mode shouldn't be to crash in sanitizer_common internals.

Patch By: mcgrathr

Differential Revision: https://reviews.llvm.org/D46344

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc?rev=331382&r1=331381&r2=331382&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc Wed May  2 11:08:47 2018
@@ -431,8 +431,10 @@ const char *GetEnv(const char *name) {
 }
 
 uptr ReadBinaryName(/*out*/ char *buf, uptr buf_len) {
-  const char *argv0 = StoredArgv[0];
-  if (!argv0) argv0 = "<UNKNOWN>";
+  const char *argv0 = "<UNKNOWN>";
+  if (StoredArgv && StoredArgv[0]) {
+    argv0 = StoredArgv[0];
+  }
   internal_strncpy(buf, argv0, buf_len);
   return internal_strlen(buf);
 }




More information about the llvm-commits mailing list