Cherry-pick upstream r299036 from libsanitizer (PR sanitizer/80166).
authorMartin Liska <mliska@suse.cz>
Thu, 6 Apr 2017 13:42:24 +0000 (15:42 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Thu, 6 Apr 2017 13:42:24 +0000 (13:42 +0000)
2017-04-06  Martin Liska  <mliska@suse.cz>

PR sanitizer/80166
* sanitizer_common/sanitizer_common_interceptors.inc (INTERCEPTOR):
Cherry-pick upstream r299036.
2017-04-06  Martin Liska  <mliska@suse.cz>

PR sanitizer/80166
* gcc.dg/asan/pr80166.c: New test.

From-SVN: r246730

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/asan/pr80166.c [new file with mode: 0644]
libsanitizer/ChangeLog
libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc

index 8f1ddc418705acc8a837d374e707cbc986ae8a66..32f5507a33273d852cc3ef9bef4ea2ddbf794706 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-06  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/80166
+       * gcc.dg/asan/pr80166.c: New test.
+
 2017-04-06  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        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 (file)
index 0000000..629dd23
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR sanitizer/80166 */
+/* { dg-do run } */
+
+#include <sys/types.h>
+#include <unistd.h>
+
+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;
+}
index 1beb8d583210646c286f55e0880faf5236a6fbd3..106e168007c8948b0f804a038d826ffe167d840a 100644 (file)
@@ -1,3 +1,9 @@
+2017-04-06  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/80166
+       * sanitizer_common/sanitizer_common_interceptors.inc (INTERCEPTOR):
+       Cherry-pick upstream r299036.
+
 2017-03-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR sanitizer/78158
index 0970eda5ee644bb69c8139c9833710a59b249abc..195014022a045774fa631e07a7795431377ec7f9 100644 (file)
@@ -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);