diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2018-05-24 16:36:35 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-26 00:21:46 -0700 |
commit | 5b7c78edd7714a38f80ccf1525f967b496410c43 (patch) | |
tree | 5c40cb64ef59c49d269f44d47937e6607623a2f5 /test | |
parent | c50523e1d1e164d8babf9ea2d8dedb741424a66c (diff) | |
download | chrome-ec-5b7c78edd7714a38f80ccf1525f967b496410c43.tar.gz |
test/utils: Fix memchr test
memchr does not take into account end of string, so the test
`memchr("123", '4', 8)` actually does a buffer overflow. On some
boards, a '4' might be found in the 4 bytes that follow "123", and
the test might fail.
Fix another potential overflow as well.
BRANCH=none
BUG=none
TEST=Flash test-utils to hammer, test passes
Change-Id: I53755c0855bbd5b180801e4198341de1cec7b425
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1071409
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/utils.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/test/utils.c b/test/utils.c index c382a46828..b3ed2fc9dc 100644 --- a/test/utils.c +++ b/test/utils.c @@ -182,9 +182,9 @@ static int test_memchr(void) { char *buf = "1234"; - TEST_ASSERT(memchr("123", '4', 8) == NULL); + TEST_ASSERT(memchr("123567890", '4', 8) == NULL); TEST_ASSERT(memchr("123", '3', 2) == NULL); - TEST_ASSERT(memchr(buf, '3', 8) == buf + 2); + TEST_ASSERT(memchr(buf, '3', 4) == buf + 2); TEST_ASSERT(memchr(buf, '4', 4) == buf + 3); return EC_SUCCESS; } |