diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-25 03:13:46 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-26 01:30:06 +0000 |
commit | 9c03439ad09f6f23ca634685d5b0b9cac8b03a88 (patch) | |
tree | 6482d50c777dc73745f6c912269394056d01eee6 /auto_tests/messenger_test.c | |
parent | 2a5941c9f9c355475fc2a75759d1daedbd77ea97 (diff) |
Fix out of bounds read in error case in messenger_test.
Also got rid of two VLAs. They are overused a bit in toxcore. In
irc_syncbot, the array was uninitialised and then filled by a recv system
call. This can cause uninitialised reads if recv doesn't fill the entire
array. It could not cause out of bounds read directly, because a
NUL-terminator was in place, but both cases are undefined behaviour.
Diffstat (limited to 'auto_tests/messenger_test.c')
-rw-r--r-- | auto_tests/messenger_test.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 614b1057..8ab185a0 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c | |||
@@ -184,8 +184,8 @@ END_TEST | |||
184 | START_TEST(test_getself_name) | 184 | START_TEST(test_getself_name) |
185 | { | 185 | { |
186 | const char *nickname = "testGallop"; | 186 | const char *nickname = "testGallop"; |
187 | int len = strlen(nickname); | 187 | size_t len = strlen(nickname); |
188 | VLA(char, nick_check, len); | 188 | char *nick_check = (char *)calloc(len + 1, 1); |
189 | 189 | ||
190 | setname(m, (const uint8_t *)nickname, len); | 190 | setname(m, (const uint8_t *)nickname, len); |
191 | getself_name(m, (uint8_t *)nick_check); | 191 | getself_name(m, (uint8_t *)nick_check); |
@@ -193,6 +193,7 @@ START_TEST(test_getself_name) | |||
193 | ck_assert_msg((memcmp(nickname, nick_check, len) == 0), | 193 | ck_assert_msg((memcmp(nickname, nick_check, len) == 0), |
194 | "getself_name failed to return the known name!\n" | 194 | "getself_name failed to return the known name!\n" |
195 | "known name: %s\nreturned: %s\n", nickname, nick_check); | 195 | "known name: %s\nreturned: %s\n", nickname, nick_check); |
196 | free(nick_check); | ||
196 | } | 197 | } |
197 | END_TEST | 198 | END_TEST |
198 | 199 | ||