summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-05-14 12:32:40 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2014-05-14 12:32:40 +0000
commite26f614dc9bba79d66a35b6ed6d195c7a13d9716 (patch)
treebcc900c4462c2c34b969fde4c0b04c742a0c5021 /test
parent5c4e6cbe3855f8716ba01985a9543a5edcebff07 (diff)
[sanitizer] Fix crash in getgrnam_r and similar interceptors.
When no matching record is found, getgrnam_r return 0 but sets result to NULL. Should fix PR19734. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc b/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc
new file mode 100644
index 000000000..a8b51d7a9
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Linux/getpwnam_r_invalid_user.cc
@@ -0,0 +1,19 @@
+// Regression test for a crash in getpwnam_r and similar interceptors.
+// RUN: %clangxx -O0 -g %s -o %t && %run %t
+
+#include <assert.h>
+#include <pwd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+int main(void) {
+ struct passwd pwd;
+ struct passwd *pwdres;
+ char buf[10000];
+ int res = getpwnam_r("no-such-user", &pwd, buf, sizeof(buf), &pwdres);
+ assert(res == 0);
+ assert(pwdres == 0);
+ return 0;
+}