[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

llvm-svn: 319344
This commit is contained in:
Kuba Mracek 2017-11-29 19:33:35 +00:00
parent 18bec60bc2
commit 21e6efcb51
2 changed files with 17 additions and 1 deletions

View File

@ -1724,7 +1724,8 @@ static void unpoison_group(void *ctx, __sanitizer_group *grp) {
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;

View File

@ -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.