libiberty: avoid reading past end of buffer in strndup/xstrndup (PR c/78498)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 30 Nov 2016 14:50:43 +0000 (14:50 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 30 Nov 2016 14:50:43 +0000 (14:50 +0000)
commite613205cefe50e429bafba2bc4cb71126b1f36df
treef30b1f41724d3288f8bdba58298d4d1aecd8960d
parente6383ae7a73164277026cf815315e39f281e6aca
libiberty: avoid reading past end of buffer in strndup/xstrndup (PR c/78498)

gcc/ChangeLog:
PR c/78498
* selftest.c (selftest::assert_strndup_eq): New function.
(selftest::test_strndup): New function.
(selftest::test_libiberty): New function.
(selftest::selftest_c_tests): Call test_libiberty.

gcc/testsuite/ChangeLog:
PR c/78498
* gcc.dg/format/pr78494.c: New test case.

libiberty/ChangeLog:
PR c/78498
* strndup.c (strlen): Delete decl.
(strnlen): Add decl.
(strndup): Call strnlen rather than strlen.
* xstrndup.c (xstrndup): Likewise.

From-SVN: r243030
gcc/ChangeLog
gcc/selftest.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/pr78494.c [new file with mode: 0644]
libiberty/ChangeLog
libiberty/strndup.c
libiberty/xstrndup.c