diff options
author | Patrick Steinhardt <ps@pks.im> | 2018-10-18 12:04:07 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-10-18 12:04:07 +0200 |
commit | 8d7fa88a9d5011b653035497b0f523e0f177b6a6 (patch) | |
tree | 6dd65abfe18ccb824438b2adb1acd77f7087f012 /tests/core | |
parent | 2613fbb26a3e1a34dda8a5d198c108626cfd6cc3 (diff) | |
download | libgit2-8d7fa88a9d5011b653035497b0f523e0f177b6a6.tar.gz |
util: remove `git__strtol32`
The function `git__strtol32` can easily be misused when untrusted data
is passed to it that may not have been sanitized with trailing `NUL`
bytes. As all usages of this function have now been removed, we can
remove this function altogether to avoid future misuse of it.
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/strtol.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/tests/core/strtol.c b/tests/core/strtol.c index 30109b438..c35f18212 100644 --- a/tests/core/strtol.c +++ b/tests/core/strtol.c @@ -1,20 +1,16 @@ #include "clar_libgit2.h" -void test_core_strtol__int32(void) +static void assert_l32_parses(const char *string, int32_t expected, int base) { int32_t i; + cl_git_pass(git__strntol32(&i, string, strlen(string), NULL, base)); + cl_assert_equal_i(i, expected); +} - cl_git_pass(git__strtol32(&i, "123", NULL, 10)); - cl_assert(i == 123); - cl_git_pass(git__strtol32(&i, " +123 ", NULL, 10)); - cl_assert(i == 123); - cl_git_pass(git__strtol32(&i, " +2147483647 ", NULL, 10)); - cl_assert(i == 2147483647); - cl_git_pass(git__strtol32(&i, " -2147483648 ", NULL, 10)); - cl_assert(i == -2147483648LL); - - cl_git_fail(git__strtol32(&i, " 2147483657 ", NULL, 10)); - cl_git_fail(git__strtol32(&i, " -2147483657 ", NULL, 10)); +static void assert_l32_fails(const char *string, int base) +{ + int32_t i; + cl_git_fail(git__strntol32(&i, string, strlen(string), NULL, base)); } static void assert_l64_parses(const char *string, int64_t expected, int base) @@ -24,6 +20,17 @@ static void assert_l64_parses(const char *string, int64_t expected, int base) cl_assert_equal_i(i, expected); } +void test_core_strtol__int32(void) +{ + assert_l32_parses("123", 123, 10); + assert_l32_parses(" +123 ", 123, 10); + assert_l32_parses(" +2147483647 ", 2147483647, 10); + assert_l32_parses(" -2147483648 ", -2147483648LL, 10); + + assert_l32_fails(" 2147483657 ", 10); + assert_l32_fails(" -2147483657 ", 10); +} + void test_core_strtol__int64(void) { assert_l64_parses("123", 123, 10); |