grep-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grep branch, master, updated. v2.21-18-g3d6cd21


From: Jim Meyering
Subject: grep branch, master, updated. v2.21-18-g3d6cd21
Date: Thu, 12 Feb 2015 04:45:18 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  3d6cd2129e0454c537b315ce0a3aab8e032fa76a (commit)
      from  fbc60d437bcaa586801441677bb1dccc1f7077d8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=3d6cd2129e0454c537b315ce0a3aab8e032fa76a


commit 3d6cd2129e0454c537b315ce0a3aab8e032fa76a
Author: Jim Meyering <address@hidden>
Date:   Wed Feb 11 12:12:23 2015 -0800

    maint: use ASAN-poisoning more carefully
    
    The ASAN-poisoning instituted by commit v2.21-14-g1555185 was
    incomplete, since the poisoned tail of the read buffer could well
    be the target of a legitimate follow-on read.  To accommodate that,
    we must unpoison each such region just before beginning fillbuf's
    read loop.
    * src/grep.c [HAVE_ASAN] (asan_poison): Define.
    (clear_asan_poison): Define.
    (fillbuf): Clear before reading, since we are likely to read
    into memory that was poisoned on the preceding iteration.
    * tests/two-files: New file, to test for this.
    * tests/Makefile.am (TESTS): Add it.

diff --git a/src/grep.c b/src/grep.c
index 7d70f4a..f720a8a 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -80,6 +80,32 @@ static bool only_matching;
 /* If nonzero, make sure first content char in a line is on a tab stop. */
 static bool align_tabs;
 
+#if HAVE_ASAN
+/* Record the starting address and length of the sole poisoned region,
+   so that we can unpoison it later, just before each following read.  */
+static void const *poison_buf;
+static size_t poison_len;
+
+static void
+clear_asan_poison (void)
+{
+  if (poison_buf)
+    __asan_unpoison_memory_region (poison_buf, poison_len);
+}
+
+static void
+asan_poison (void const *addr, size_t size)
+{
+  poison_buf = addr;
+  poison_len = size;
+
+  __asan_poison_memory_region (poison_buf, poison_len);
+}
+#else
+static void clear_asan_poison (void) { }
+static void asan_poison (void const volatile *addr, size_t size) { }
+#endif
+
 /* The group separator used when context is requested. */
 static const char *group_separator = SEP_STR_GROUP;
 
@@ -773,6 +799,8 @@ fillbuf (size_t save, struct stat const *st)
         }
     }
 
+  clear_asan_poison ();
+
   readsize = buffer + bufalloc - sizeof (uword) - readbuf;
   readsize -= readsize % pagesize;
 
@@ -818,8 +846,8 @@ fillbuf (size_t save, struct stat const *st)
 
   /* Mark the part of the buffer not filled by the read or set by
      the above memset call as ASAN-poisoned.  */
-  __asan_poison_memory_region (buflim + sizeof (uword),
-                               bufalloc - (buflim - buffer) - sizeof (uword));
+  asan_poison (buflim + sizeof (uword),
+               bufalloc - (buflim - buffer) - sizeof (uword));
 
   return cc;
 }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8fcf8f6..33b6adc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -114,6 +114,7 @@ TESTS =                                             \
   surrogate-pair                               \
   symlink                                      \
   triple-backref                               \
+  two-files                                    \
   turkish-eyes                                 \
   turkish-I                                    \
   turkish-I-without-dot                                \
diff --git a/tests/two-files b/tests/two-files
new file mode 100755
index 0000000..d655e56
--- /dev/null
+++ b/tests/two-files
@@ -0,0 +1,22 @@
+#! /bin/sh
+# Read two files, of increasing size.
+# With ASAN, this would have triggered a false-positive read of poisoned 
memory.
+#
+# Copyright 2015 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+printf a > 1 || framework_failure_
+printf ab > 2 || framework_failure_
+
+grep x 1 2 > out 2>&1
+test $? -eq 1 || fail=1
+compare /dev/null out || fail=1
+
+Exit $fail

-----------------------------------------------------------------------

Summary of changes:
 src/grep.c                      |   32 ++++++++++++++++++++++++++++++--
 tests/Makefile.am               |    1 +
 tests/{pcre-abort => two-files} |   15 ++++++++-------
 3 files changed, 39 insertions(+), 9 deletions(-)
 copy tests/{pcre-abort => two-files} (50%)


hooks/post-receive
-- 
grep



reply via email to

[Prev in Thread] Current Thread [Next in Thread]