diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-11-30 14:50:43 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-11-30 14:50:43 +0000 |
commit | e613205cefe50e429bafba2bc4cb71126b1f36df (patch) | |
tree | f30b1f41724d3288f8bdba58298d4d1aecd8960d /libiberty/xstrndup.c | |
parent | e6383ae7a73164277026cf815315e39f281e6aca (diff) | |
download | gcc-e613205cefe50e429bafba2bc4cb71126b1f36df.tar.gz |
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
Diffstat (limited to 'libiberty/xstrndup.c')
-rw-r--r-- | libiberty/xstrndup.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/libiberty/xstrndup.c b/libiberty/xstrndup.c index 0a41f608ec0..c3d2d833902 100644 --- a/libiberty/xstrndup.c +++ b/libiberty/xstrndup.c @@ -48,10 +48,7 @@ char * xstrndup (const char *s, size_t n) { char *result; - size_t len = strlen (s); - - if (n < len) - len = n; + size_t len = strnlen (s, n); result = XNEWVEC (char, len + 1); |