summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-10-18 12:04:07 +0200
committerPatrick Steinhardt <ps@pks.im>2018-10-26 14:20:35 +0200
commite2e7a9cbac0d3028fed23a911b2241d412fdf58b (patch)
tree7abed7caab9397095bb04034e8ac446f59345f2e
parent2052a3cd6aeb664c79336fbd572ddc72d95a49d7 (diff)
downloadlibgit2-e2e7a9cbac0d3028fed23a911b2241d412fdf58b.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. (cherry picked from commit 8d7fa88a9d5011b653035497b0f523e0f177b6a6)
-rw-r--r--src/util.c6
-rw-r--r--src/util.h1
-rw-r--r--tests/core/strtol.c31
3 files changed, 19 insertions, 19 deletions
diff --git a/src/util.c b/src/util.c
index 952af0206..af041b728 100644
--- a/src/util.c
+++ b/src/util.c
@@ -150,12 +150,6 @@ Return:
return 0;
}
-int git__strtol32(int32_t *result, const char *nptr, const char **endptr, int base)
-{
-
- return git__strntol32(result, nptr, (size_t)-1, endptr, base);
-}
-
int git__strntol32(int32_t *result, const char *nptr, size_t nptr_len, const char **endptr, int base)
{
int error;
diff --git a/src/util.h b/src/util.h
index 30ab9e8b5..fddf36ab9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -193,7 +193,6 @@ GIT_INLINE(int) git__signum(int val)
return ((val > 0) - (val < 0));
}
-extern int git__strtol32(int32_t *n, const char *buff, const char **end_buf, int base);
extern int git__strntol32(int32_t *n, const char *buff, size_t buff_len, const char **end_buf, int base);
extern int git__strntol64(int64_t *n, const char *buff, size_t buff_len, const char **end_buf, int base);
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);