Skip to content

Commit 9213cbd

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331382 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2b275a9 commit 9213cbd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/sanitizer_common/sanitizer_fuchsia.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,10 @@ const char *GetEnv(const char *name) {
431431
}
432432

433433
uptr ReadBinaryName(/*out*/ char *buf, uptr buf_len) {
434-
const char *argv0 = StoredArgv[0];
435-
if (!argv0) argv0 = "<UNKNOWN>";
434+
const char *argv0 = "<UNKNOWN>";
435+
if (StoredArgv && StoredArgv[0]) {
436+
argv0 = StoredArgv[0];
437+
}
436438
internal_strncpy(buf, argv0, buf_len);
437439
return internal_strlen(buf);
438440
}

0 commit comments

Comments
 (0)