[PATCH] D46344: [sanitizer] Fix Fuchsia ReadBinaryName not to crash when uninitialized

Roland McGrath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 1 18:35:36 PDT 2018


mcgrathr created this revision.
mcgrathr added reviewers: phosek, cryptoad.
mcgrathr added a project: Sanitizers.
Herald added a subscriber: kubamracek.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D46344

Files:
  lib/sanitizer_common/sanitizer_fuchsia.cc


Index: lib/sanitizer_common/sanitizer_fuchsia.cc
===================================================================
--- lib/sanitizer_common/sanitizer_fuchsia.cc
+++ lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -431,8 +431,10 @@
 }
 
 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);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46344.144821.patch
Type: text/x-patch
Size: 549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180502/b6db4df0/attachment.bin>


More information about the llvm-commits mailing list