From: Jouni Malinen Date: Mon, 2 Jun 2014 12:49:54 +0000 (+0300) Subject: tests: printf_encode unit test for bounds checking X-Git-Tag: hostap_2_2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee54e4010e57c68422d1db8d7388dcf001d3db7d;p=thirdparty%2Fhostap.git tests: printf_encode unit test for bounds checking Signed-off-by: Jouni Malinen --- diff --git a/src/utils/utils_module_tests.c b/src/utils/utils_module_tests.c index 75b169e62..9a9ec4001 100644 --- a/src/utils/utils_module_tests.c +++ b/src/utils/utils_module_tests.c @@ -67,6 +67,23 @@ static int printf_encode_decode_tests(void) } } + buf[5] = 'A'; + printf_encode(buf, 5, (const u8 *) "abcde", 5); + if (buf[5] != 'A') { + wpa_printf(MSG_ERROR, "Error in bounds checking#1"); + errors++; + } + + for (i = 5; i < 10; i++) { + buf[i] = 'A'; + printf_encode(buf, i, (const u8 *) "\xdd\xdd\xdd\xdd\xdd", 5); + if (buf[i] != 'A') { + wpa_printf(MSG_ERROR, "Error in bounds checking#2(%d)", + i); + errors++; + } + } + if (errors) { wpa_printf(MSG_ERROR, "%d printf test(s) failed", errors); return -1;