quotearg: do not read beyond end of buffer
authorJim Meyering <meyering@fb.com>
Sun, 12 May 2013 01:43:50 +0000 (18:43 -0700)
committerJim Meyering <jim@meyering.net>
Tue, 14 May 2013 01:27:07 +0000 (03:27 +0200)
commit26c6620f1799962b5f31cb8d66e79d73762fd160
tree1e50c949044d0a46355090a23e5875cb2e867552
parent3fe906e98202a591a6a14010aec1538adfd821b6
quotearg: do not read beyond end of buffer

* lib/quotearg.c (quotearg_buffer_restyled): Do not read beyond the
end of an ARG for which no length was specified.  With an N-byte
quote string, (e.g., N is 3 in the fr_FR.UTF-8 locale), this function
would read N-2 bytes beyond ARG's trailing NUL.  This was triggered
via coreutils' misc/sort-debug-keys.sh test and detected by running
the test against a binary compiled with gcc-4.8.0's -fsanitize=address.
* tests/test-quotearg-simple.c (main): Add a test to trigger the bug.
* modules/quotearg-simple-tests (Files): Add tests/zerosize-ptr.h.
Introduced via the 2000-01-15 commit, c4b7f3f8, "Quote multibyte
characters correctly."
ChangeLog
lib/quotearg.c
modules/quotearg-simple-tests
tests/test-quotearg-simple.c