[compiler-rt] r319344 - [asan] Allow getpwnam(NULL) for binary compatibility
Kuba Mracek via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 29 11:33:35 PST 2017
Author: kuba.brecka
Date: Wed Nov 29 11:33:35 2017
New Revision: 319344
URL: http://llvm.org/viewvc/llvm-project?rev=319344&view=rev
Log:
[asan] Allow getpwnam(NULL) for binary compatibility
Calling getpwnam(NULL) is probably a bug, but at least on Darwin, such a call succeeds without segfaulting. I have some existing code that relies on that. To maintain binary compatibility, ASan should also survive a call to getpwnam with NULL.
Differential Revision: https://reviews.llvm.org/D40052
Added:
compiler-rt/trunk/test/asan/TestCases/Darwin/getpwnam.c
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=319344&r1=319343&r2=319344&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Wed Nov 29 11:33:35 2017
@@ -1724,7 +1724,8 @@ static void unpoison_group(void *ctx, __
INTERCEPTOR(__sanitizer_passwd *, getpwnam, const char *name) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, getpwnam, name);
- COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1);
+ if (name)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, name, REAL(strlen)(name) + 1);
__sanitizer_passwd *res = REAL(getpwnam)(name);
if (res) unpoison_passwd(ctx, res);
return res;
Added: compiler-rt/trunk/test/asan/TestCases/Darwin/getpwnam.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/getpwnam.c?rev=319344&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/getpwnam.c (added)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/getpwnam.c Wed Nov 29 11:33:35 2017
@@ -0,0 +1,15 @@
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+int main(int argc, const char * argv[]) {
+ getpwnam(NULL);
+ fprintf(stderr, "Finished.\n");
+ return 0;
+}
+
+// CHECK: Finished.
More information about the llvm-commits
mailing list