[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:
parent
18bec60bc2
commit
21e6efcb51
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
Loading…
Reference in New Issue