]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[libc] Prevent strndup() from reading beyond the end of the string
authorMichael Brown <mcb30@ipxe.org>
Sun, 18 May 2014 20:05:39 +0000 (21:05 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sun, 18 May 2014 20:09:49 +0000 (21:09 +0100)
commit2b4be69eee372e1010af2302e82c3d0cf1d875e9
tree29a68f744d7df70437b8e3ede82e98c3d4c9de9e
parent524936895089772a3d1eac629b5f978fa076a161
[libc] Prevent strndup() from reading beyond the end of the string

strndup() may be called on a string which is not NUL-terminated.  Use
strnlen() instead of strlen() to ensure that we do not read beyond the
end of such a string.

Add self-tests for strndup(), including a test case with an
unterminated string.

Originally-fixed-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/string.c
src/tests/string_test.c