From d9f8c5af8bc43681764923379dc465b62b56877a Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Thu, 6 Apr 2017 15:42:24 +0200 Subject: [PATCH] Cherry-pick upstream r299036 from libsanitizer (PR sanitizer/80166). 2017-04-06 Martin Liska PR sanitizer/80166 * sanitizer_common/sanitizer_common_interceptors.inc (INTERCEPTOR): Cherry-pick upstream r299036. 2017-04-06 Martin Liska PR sanitizer/80166 * gcc.dg/asan/pr80166.c: New test. From-SVN: r246730 --- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/asan/pr80166.c | 24 +++++++++++++++++++ libsanitizer/ChangeLog | 6 +++++ .../sanitizer_common_interceptors.inc | 3 ++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/asan/pr80166.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8f1ddc41870..32f5507a332 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-06 Martin Liska + + PR sanitizer/80166 + * gcc.dg/asan/pr80166.c: New test. + 2017-04-06 Rainer Orth PR tree-optimization/79390 diff --git a/gcc/testsuite/gcc.dg/asan/pr80166.c b/gcc/testsuite/gcc.dg/asan/pr80166.c new file mode 100644 index 00000000000..629dd23a31c --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr80166.c @@ -0,0 +1,24 @@ +/* PR sanitizer/80166 */ +/* { dg-do run } */ + +#include +#include + +int +main (int argc, char **argv) +{ + gid_t groups; + int r = getgroups (0, &groups); + if (r < 0) + __builtin_abort (); + + r = getgroups (-1, &groups); + if (r != -1) + __builtin_abort (); + + r = getgroups (-1, NULL); + if (r != -1) + __builtin_abort (); + + return 0; +} diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog index 1beb8d58321..106e168007c 100644 --- a/libsanitizer/ChangeLog +++ b/libsanitizer/ChangeLog @@ -1,3 +1,9 @@ +2017-04-06 Martin Liska + + PR sanitizer/80166 + * sanitizer_common/sanitizer_common_interceptors.inc (INTERCEPTOR): + Cherry-pick upstream r299036. + 2017-03-22 Jakub Jelinek PR sanitizer/78158 diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc index 0970eda5ee6..195014022a0 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc +++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc @@ -3350,7 +3350,8 @@ INTERCEPTOR(int, getgroups, int size, u32 *lst) { // its metadata. See // https://github.com/google/sanitizers/issues/321. int res = REAL(getgroups)(size, lst); - if (res && lst) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lst, res * sizeof(*lst)); + if (res >= 0 && lst && size > 0) + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, lst, res * sizeof(*lst)); return res; } #define INIT_GETGROUPS COMMON_INTERCEPT_FUNCTION(getgroups); -- 2.30.2