1// Regression test for a crash in getpwnam_r and similar interceptors.
2// RUN: %clangxx -O0 -g %s -o %t && %run %t
3
4#include <assert.h>
5#include <errno.h>
6#include <pwd.h>
7#include <signal.h>
8#include <stdio.h>
9#include <sys/types.h>
10#include <unistd.h>
11
12int main(void) {
13 struct passwd pwd;
14 struct passwd *pwdres;
15 char buf[10000];
16 int res = getpwnam_r(name: "no-such-user", resultbuf: &pwd, buffer: buf, buflen: sizeof(buf), result: &pwdres);
17 assert(res == 0 || res == ENOENT);
18 assert(pwdres == 0);
19 return 0;
20}
21

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cpp