diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -2431,14 +2431,26 @@ char *const envp[]) { COMMON_INTERCEPTOR_READ_RANGE(ctx, file_or_path, internal_strlen(file_or_path) + 1); - char *const *s = argv; - for (; *s; ++s) - COMMON_INTERCEPTOR_READ_RANGE(ctx, *s, internal_strlen(*s) + 1); - COMMON_INTERCEPTOR_READ_RANGE(ctx, argv, (s - argv + 1) * sizeof(*s)); - s = envp; - for (; *s; ++s) - COMMON_INTERCEPTOR_READ_RANGE(ctx, *s, internal_strlen(*s) + 1); - COMMON_INTERCEPTOR_READ_RANGE(ctx, envp, (s - envp + 1) * sizeof(*s)); +#if SANITIZER_LINUX + if (argv) { +#endif + for (char *const *s = argv; ; ++s) { + COMMON_INTERCEPTOR_READ_RANGE(ctx, s, sizeof(*s)); + if (!*s) break; + COMMON_INTERCEPTOR_READ_RANGE(ctx, *s, internal_strlen(*s) + 1); + } +#if SANITIZER_LINUX + } + if (envp) { +#endif + for (char *const *s = envp; ; ++s) { + COMMON_INTERCEPTOR_READ_RANGE(ctx, s, sizeof(*s)); + if (!*s) break; + COMMON_INTERCEPTOR_READ_RANGE(ctx, *s, internal_strlen(*s) + 1); + } +#if SANITIZER_LINUX + } +#endif int res = real_posix_spawn(pid, file_or_path, file_actions, attrp, argv, envp); if (res == 0)