[PATCH] D40052: [asan] Allow getpwnam(NULL) for binary compatibily
Kuba (Brecka) Mracek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 15:18:19 PST 2017
kubamracek created this revision.
kubamracek added a project: Sanitizers.
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`.
Repository:
rL LLVM
https://reviews.llvm.org/D40052
Files:
lib/sanitizer_common/sanitizer_common_interceptors.inc
test/asan/TestCases/Darwin/getpwnam.c
Index: test/asan/TestCases/Darwin/getpwnam.c
===================================================================
--- test/asan/TestCases/Darwin/getpwnam.c
+++ test/asan/TestCases/Darwin/getpwnam.c
@@ -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.
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -1724,7 +1724,8 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40052.122925.patch
Type: text/x-patch
Size: 1161 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171114/af0d82de/attachment.bin>
More information about the llvm-commits
mailing list