summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-10-18 11:58:14 +0200
committerPatrick Steinhardt <ps@pks.im>2018-10-26 14:20:35 +0200
commit2052a3cd6aeb664c79336fbd572ddc72d95a49d7 (patch)
treebde1d99164ac38c969881901fbc3bb18a397d110
parent61165dd4003938ce5b2e684799760cc7c0c82e9e (diff)
downloadlibgit2-2052a3cd6aeb664c79336fbd572ddc72d95a49d7.tar.gz
global: replace remaining use of `git__strtol32`
Replace remaining uses of the `git__strtol32` function. While these uses are all safe as the strings were either sanitized or from a trusted source, we want to remove `git__strtol32` altogether to avoid future misuse. (cherry picked from commit 2613fbb26a3e1a34dda8a5d198c108626cfd6cc3)
-rw-r--r--src/rebase.c2
-rw-r--r--src/revparse.c5
-rw-r--r--src/streams/curl.c2
-rw-r--r--src/transports/smart_pkt.c2
-rw-r--r--src/transports/winhttp.c3
5 files changed, 8 insertions, 6 deletions
diff --git a/src/rebase.c b/src/rebase.c
index 3be751254..52211ad11 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -152,7 +152,7 @@ GIT_INLINE(int) rebase_readint(
if ((error = rebase_readfile(asc_out, state_path, filename)) < 0)
return error;
- if (git__strtol32(&num, asc_out->ptr, &eol, 10) < 0 || num < 0 || *eol) {
+ if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) {
giterr_set(GITERR_REBASE, "the file '%s' contains an invalid numeric value", filename);
return -1;
}
diff --git a/src/revparse.c b/src/revparse.c
index 7cb22f476..f96f9bada 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -128,7 +128,8 @@ static int try_parse_numeric(int *n, const char *curly_braces_content)
int32_t content;
const char *end_ptr;
- if (git__strtol32(&content, curly_braces_content, &end_ptr, 10) < 0)
+ if (git__strntol32(&content, curly_braces_content, strlen(curly_braces_content),
+ &end_ptr, 10) < 0)
return -1;
if (*end_ptr != '\0')
@@ -578,7 +579,7 @@ static int extract_how_many(int *n, const char *spec, size_t *pos)
} while (spec[(*pos)] == kind && kind == '~');
if (git__isdigit(spec[*pos])) {
- if (git__strtol32(&parsed, spec + *pos, &end_ptr, 10) < 0)
+ if (git__strntol32(&parsed, spec + *pos, strlen(spec + *pos), &end_ptr, 10) < 0)
return GIT_EINVALIDSPEC;
accumulated += (parsed - 1);
diff --git a/src/streams/curl.c b/src/streams/curl.c
index ee13be1dc..3c0af3b04 100644
--- a/src/streams/curl.c
+++ b/src/streams/curl.c
@@ -330,7 +330,7 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)
return -1;
}
- if ((error = git__strtol32(&iport, port, NULL, 10)) < 0) {
+ if ((error = git__strntol32(&iport, port, strlen(port), NULL, 10)) < 0) {
git__free(st);
return error;
}
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index e726d0777..0e05ff861 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -391,7 +391,7 @@ static int parse_len(size_t *out, const char *line, size_t linelen)
}
}
- if ((error = git__strtol32(&len, num, &num_end, 16)) < 0)
+ if ((error = git__strntol32(&len, num, PKT_LEN_SIZE, &num_end, 16)) < 0)
return error;
if (len < 0)
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index e52d54b6d..4a1eb0490 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -761,7 +761,8 @@ static int winhttp_connect(
t->connection = NULL;
/* Prepare port */
- if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0)
+ if (git__strntol32(&port, t->connection_data.port,
+ strlen(t->connection_data.port), NULL, 10) < 0)
return -1;
/* Prepare host */