Subject: Re: [Grep-devel] bug#25390: Segfault with sed 4.3

From: Jim Meyering <[email-masked]>
Date: Sat, 14 Jan 2017 15:40:31 -0800

On Mon, Jan 9, 2017 at 9:27 PM, Assaf Gordon <[email-masked]> wrote:
> Hello all,
>
>> On Jan 9, 2017, at 09:11, Norihiro Tanaka <[email-masked]> wrote:
>>
>> Sorry, I adjusted commit log, New patch does not change
>> testsuite/Makefile.tests.
>> <0001-tests-new-test-for-dfa-crash-bug.patch>
>
>
> Paul,
> Thank you for the quick fix.
>
> Norihiro,
> Thank you for the dfa improvements and sed-tests.
>
> Using your example of:
>    printf '0123456789abcd\nx\n' | valgrind ./sed/sed 'N;s/0123456789abcd\n//'
> I wasn't able to trigger the segfault (or even a valgrind warning) on sed-4.3 / x86_64.
>
> I suggest modifying the input just a bit, making it slightly more similar to the original bug report - with it I'm able to always reproduce the segfault:
>    printf "abcdefg abcdefg\nB\n" | valgrind ./sed/sed 'N;s/abcdefg.*\n//'
>
> What do you think ?
>
> I'm also considering duplicating the test - once with and once without valgrind.
> Is this warranted or an overkill ?
>
> Attach patch contains updated tests (and slightly modified git-comment).
> The second commit updates gnulib (comes after adding the tests just temporarily, to make testing before/after gnulib update easier).

Hi Assaf,

Thank you for adjusting the tests and commit log. Those look fine.

The only problem is that the new newline-valgrind.sh test would fail
when run against an ASAN-enabled sed. That is because valgrind just
doesn't work when the binary is ASAN-enabled. So I have extemded
init.cfg's require_valgrind_ function so that it also detects this
case and skips the test. I will push the attached shortly, after which
you are welcome to push your commits.
From 1d7ee2d5532918c953a339ec11f0624a1beb2604 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email-masked]>
Date: Sat, 14 Jan 2017 15:32:41 -0800
Subject: [PATCH] tests: skip valgrind-running tests when ASAN-enabled

* init.cfg (require_valgrind_): Skip when we detect that the
binary is ASAN-enabled.
---
 init.cfg | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/init.cfg b/init.cfg
index 25c68d6..915a260 100644
--- a/init.cfg
+++ b/init.cfg
@@ -23,10 +23,17 @@ stderr_fileno_=9
 # which could happen if not installed,
 # or hasn't support for the built architecture,
 # or hasn't appropriate error suppressions installed etc.
+# or the program under test was compiled with address sanitizer.
 require_valgrind_()
 {
   valgrind --error-exitcode=1 true 2>/dev/null ||
     skip_ "requires a working valgrind"
+
+  # We cannot apply valgrind to an ASAN-enabled executable.
+  # An ASAN-enabled binary will print this on the first line of
+  # its help output: Available flags for AddressSanitizer:
+  ASAN_OPTIONS=help=1 sed qq 2>&1 | grep AddressSanitizer: \
+    && skip_ 'ASAN enabled binary cannot work with valgrind'
 }

 # Call this with a list of programs under test immediately after
-- 
2.9.3