Skip to content

Commit bea6598

Browse files
authored
Merge pull request libgit2#4851 from pks-t/pks/strtol-removal
strtol removal
2 parents 1194546 + ea19efc commit bea6598

File tree

13 files changed

+111
-66
lines changed

13 files changed

+111
-66
lines changed

src/commit_list.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ static int commit_quick_parse(
171171
buffer--;
172172
}
173173

174-
if ((buffer == committer_start) || (git__strtol64(&commit_time, (char *)(buffer + 1), NULL, 10) < 0))
174+
if ((buffer == committer_start) ||
175+
(git__strntol64(&commit_time, (char *)(buffer + 1),
176+
buffer_end - buffer + 1, NULL, 10) < 0))
175177
return commit_error(commit, "cannot parse commit time");
176178

177179
commit->time = commit_time;

src/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ int git_config_parse_int64(int64_t *out, const char *value)
13001300
const char *num_end;
13011301
int64_t num;
13021302

1303-
if (!value || git__strtol64(&num, value, &num_end, 0) < 0)
1303+
if (!value || git__strntol64(&num, value, strlen(value), &num_end, 0) < 0)
13041304
goto fail_parse;
13051305

13061306
switch (*num_end) {

src/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,7 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
22432243
for (i = 0; i < 3; i++) {
22442244
int64_t tmp;
22452245

2246-
if (git__strtol64(&tmp, buffer, &endptr, 8) < 0 ||
2246+
if (git__strntol64(&tmp, buffer, size, &endptr, 8) < 0 ||
22472247
!endptr || endptr == buffer || *endptr ||
22482248
tmp < 0 || tmp > UINT32_MAX) {
22492249
index_entry_reuc_free(lost);

src/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ GIT_INLINE(int) rebase_readint(
152152
if ((error = rebase_readfile(asc_out, state_path, filename)) < 0)
153153
return error;
154154

155-
if (git__strtol32(&num, asc_out->ptr, &eol, 10) < 0 || num < 0 || *eol) {
155+
if (git__strntol32(&num, asc_out->ptr, asc_out->size, &eol, 10) < 0 || num < 0 || *eol) {
156156
giterr_set(GITERR_REBASE, "the file '%s' contains an invalid numeric value", filename);
157157
return -1;
158158
}

src/revparse.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ static int try_parse_numeric(int *n, const char *curly_braces_content)
128128
int32_t content;
129129
const char *end_ptr;
130130

131-
if (git__strtol32(&content, curly_braces_content, &end_ptr, 10) < 0)
131+
if (git__strntol32(&content, curly_braces_content, strlen(curly_braces_content),
132+
&end_ptr, 10) < 0)
132133
return -1;
133134

134135
if (*end_ptr != '\0')
@@ -578,7 +579,7 @@ static int extract_how_many(int *n, const char *spec, size_t *pos)
578579
} while (spec[(*pos)] == kind && kind == '~');
579580

580581
if (git__isdigit(spec[*pos])) {
581-
if (git__strtol32(&parsed, spec + *pos, &end_ptr, 10) < 0)
582+
if (git__strntol32(&parsed, spec + *pos, strlen(spec + *pos), &end_ptr, 10) < 0)
582583
return GIT_EINVALIDSPEC;
583584

584585
accumulated += (parsed - 1);

src/signature.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
231231
const char *time_start = email_end + 2;
232232
const char *time_end;
233233

234-
if (git__strtol64(&sig->when.time, time_start, &time_end, 10) < 0) {
234+
if (git__strntol64(&sig->when.time, time_start,
235+
buffer_end - time_start, &time_end, 10) < 0) {
235236
git__free(sig->name);
236237
git__free(sig->email);
237238
sig->name = sig->email = NULL;
@@ -246,7 +247,8 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
246247
tz_start = time_end + 1;
247248

248249
if ((tz_start[0] != '-' && tz_start[0] != '+') ||
249-
git__strtol32(&offset, tz_start + 1, &tz_end, 10) < 0) {
250+
git__strntol32(&offset, tz_start + 1,
251+
buffer_end - tz_start + 1, &tz_end, 10) < 0) {
250252
/* malformed timezone, just assume it's zero */
251253
offset = 0;
252254
}

src/streams/curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int git_curl_stream_new(git_stream **out, const char *host, const char *port)
330330
return -1;
331331
}
332332

333-
if ((error = git__strtol32(&iport, port, NULL, 10)) < 0) {
333+
if ((error = git__strntol32(&iport, port, strlen(port), NULL, 10)) < 0) {
334334
git__free(st);
335335
return error;
336336
}

src/transports/smart_pkt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static int parse_len(size_t *out, const char *line, size_t linelen)
391391
}
392392
}
393393

394-
if ((error = git__strtol32(&len, num, &num_end, 16)) < 0)
394+
if ((error = git__strntol32(&len, num, PKT_LEN_SIZE, &num_end, 16)) < 0)
395395
return error;
396396

397397
if (len < 0)

src/transports/winhttp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,8 @@ static int winhttp_connect(
766766
t->connection = NULL;
767767

768768
/* Prepare port */
769-
if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0)
769+
if (git__strntol32(&port, t->connection_data.port,
770+
strlen(t->connection_data.port), NULL, 10) < 0)
770771
return -1;
771772

772773
/* Prepare host */

src/tree-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int read_tree_internal(git_tree_cache **out,
9191
return -1;
9292

9393
/* Blank-terminated ASCII decimal number of entries in this tree */
94-
if (git__strtol32(&count, buffer, &buffer, 10) < 0)
94+
if (git__strntol32(&count, buffer, buffer_end - buffer, &buffer, 10) < 0)
9595
goto corrupted;
9696

9797
tree->entry_count = count;
@@ -100,7 +100,7 @@ static int read_tree_internal(git_tree_cache **out,
100100
goto corrupted;
101101

102102
/* Number of children of the tree, newline-terminated */
103-
if (git__strtol32(&count, buffer, &buffer, 10) < 0 || count < 0)
103+
if (git__strntol32(&count, buffer, buffer_end - buffer, &buffer, 10) < 0 || count < 0)
104104
goto corrupted;
105105

106106
tree->children_count = count;

0 commit comments

Comments
 (0)