Subject: Re: bug#20490: [PATCH] fixup: reference to uninitialized variable with invalid sequence

From: Norihiro Tanaka <[email-masked]>
Date: Wed, 06 May 2015 08:58:47 +0900

On Sun, 3 May 2015 10:06:00 -0700
Jim Meyering <[email-masked]> wrote:

> On Sat, May 2, 2015 at 7:09 PM, Jim Meyering <[email-masked]> wrote:
> > On Wed, Nov 5, 2014 at 7:36 AM, Norihiro Tanaka <[email-masked]> wrote:
> >> Uninitialized variable are referred with invalid sequence in
> >> str_append_modified().
> >>
> >> When mbrtowc() returns (size_t) -1, wc is not changed, even if wc is
> >> uninitialized.  below may return unexpected result in order that the
> >> value is referred at a following position in source code.
> >>
> >>   $ echo a | LC_ALL=ja_JP.eucJP ./sed/sed -e 's/a/b\U\xb2c/'
> >
> > Thank you for the patch and reproducer.
> > I've made some small improvements to the actual patch and
> > wrote a valgrind-using test that I'm adding to the test suite.
> > I've included your patch with an adjusted log, followed by
> > the changes I made to it in a separate commit. That commit
> > is separate solely to show what I've done; I will squash into your
> > commit before I push, followed by the test-adding commit.
> 
> I've updated the commit log to reference this just-closed issue,
> with this line:
> 
>   This addresses http://debbugs.gnu.org/20490
> 
> Then pushed.

I see that this bug itself is correctly fixed by the patch.

I ran new test on CentOS 5.10 (x86), and ran accross an error in
attachment even after applying the patch.
===========================================================
   GNU sed 4.2.2.81-aeb3-dirty: testsuite/test-suite.log
===========================================================

# TOTAL: 69
# PASS:  68
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

FAIL: invalid-mb-seq-UMR
========================

++ initial_cwd_=/home/staff/sed/testsuite
++ fail=0
+++ testdir_prefix_
+++ printf gt
++ pfx_=gt
+++ mktempd_ /home/staff/sed/testsuite gt-invalid-mb-seq-UMR.sh.XXXX
+++ case $# in
+++ destdir_=/home/staff/sed/testsuite
+++ template_=gt-invalid-mb-seq-UMR.sh.XXXX
+++ MAX_TRIES_=4
+++ case $destdir_ in
+++ case $template_ in
++++ unset TMPDIR
+++ d=/home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
+++ case $d in
+++ test -d /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
++++ ls -dgo /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
++++ tr S -
+++ perms='drwx------ 2 4096 May  6 08:47 /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000'
+++ case $perms in
+++ test 0 = 0
+++ echo /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
+++ return
++ test_dir_=/home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
++ cd /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
++ gl_init_sh_nl_='
'
++ IFS=' 	
'
++ for sig_ in 1 2 3 13 15
+++ expr 1 + 128
++ eval 'trap '\''Exit 129'\'' 1'
+++ trap 'Exit 129' 1
++ for sig_ in 1 2 3 13 15
+++ expr 2 + 128
++ eval 'trap '\''Exit 130'\'' 2'
+++ trap 'Exit 130' 2
++ for sig_ in 1 2 3 13 15
+++ expr 3 + 128
++ eval 'trap '\''Exit 131'\'' 3'
+++ trap 'Exit 131' 3
++ for sig_ in 1 2 3 13 15
+++ expr 13 + 128
++ eval 'trap '\''Exit 141'\'' 13'
+++ trap 'Exit 141' 13
++ for sig_ in 1 2 3 13 15
+++ expr 15 + 128
++ eval 'trap '\''Exit 143'\'' 15'
+++ trap 'Exit 143' 15
++ trap remove_tmp_ 0
+ path_prepend_ ../sed
+ test 1 '!=' 0
+ path_dir_=../sed
+ case $path_dir_ in
+ abs_path_dir_=/home/staff/sed/testsuite/../sed
+ case $abs_path_dir_ in
+ PATH=/home/staff/sed/testsuite/../sed:/home/staff/bin:/opt/git/bin:/opt/java/bin:/opt/python/bin:/opt/perl/bin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+ create_exe_shims_ /home/staff/sed/testsuite/../sed
+ case $EXEEXT in
+ return 0
+ shift
+ test 0 '!=' 0
+ export PATH
+ print_ver_ sed
+ test yes = yes
+ local i
+ for i in '$*'
+ env sed --version
sed (GNU sed) 4.2.2.81-aeb3-dirty
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <[email-masked]>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
+ require_valgrind_
+ valgrind --error-exitcode=1 true
+ echo a
+ echo bC
+ LC_ALL=ja_JP.eucJP
+ valgrind --quiet --error-exitcode=1 sed -e 's/a/b\U\xb2c/' in
+ fail=1
+ compare exp out
+ compare_dev_null_ exp out
+ test 2 = 2
+ test xexp = x/dev/null
+ test xout = x/dev/null
+ return 2
+ case $? in
+ compare_ exp out
+ diff -u exp out
--- exp	2015-05-06 08:47:37.000000000 +0900
+++ out	2015-05-06 08:47:37.000000000 +0900
@@ -1 +0,0 @@
-bC
+ fail=1
+ compare /dev/null err
+ compare_dev_null_ /dev/null err
+ test 2 = 2
+ test x/dev/null = x/dev/null
+ test -s err
+ emit_diff_u_header_ /dev/null err
+ printf '%s\n' 'diff -u /dev/null err' '--- /dev/null	1970-01-01' '+++ err	1970-01-01'
diff -u /dev/null err
--- /dev/null	1970-01-01
+++ err	1970-01-01
+ sed 's/^/+/' err
+--5016-- Warning: DWARF2 CFI reader: unhandled DW_OP_ opcode 0x2a
+
+valgrind: m_debuginfo/readdwarf.c:2262 (copy_convert_CfiExpr_tree): Assertion 'srcix >= 0 && srcix < VG_(sizeXA)(srcxa)' failed.
+==5016==    at 0x3802780D: ??? (in /usr/lib/valgrind/memcheck-x86-linux)
+
+sched status:
+  running_tid=0
+
+
+Note: see also the FAQ in the source distribution.
+It contains workarounds to several common problems.
+In particular, if Valgrind aborted or crashed after
+identifying problems in your program, there's a good chance
+that fixing those problems will prevent Valgrind aborting or
+crashing, especially if it happened in m_mallocfree.c.
+
+If that doesn't help, please report this bug to: www.valgrind.org
+
+In the bug report, send all the above text, the valgrind
+version, and what OS and version you are using.  Thanks.
+
+ return 1
+ case $? in
+ return 1
+ fail=1
+ Exit 1
+ set +e
+ exit 1
+ exit 1
+ remove_tmp_
+ __st=1
+ cleanup_
+ :
+ cd /home/staff/sed/testsuite
+ chmod -R u+rwx /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
+ rm -rf /home/staff/sed/testsuite/gt-invalid-mb-seq-UMR.sh.5000
+ exit 1
FAIL invalid-mb-seq-UMR.sh (exit status: 1)