Skip to content

Commit 63b77ed

Browse files
committed
Merge branch 'ua/atoi' into seen
* ua/atoi: imap: replace atoi() with strtol_i() for UIDVALIDITY and UIDNEXT parsing merge: replace atoi() with strtol_i() for marker size validation daemon: replace atoi() with strtoul_ui() and strtol_i()
2 parents b8ce139 + ef90600 commit 63b77ed

File tree

5 files changed

+52
-12
lines changed

5 files changed

+52
-12
lines changed

daemon.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,17 +1308,20 @@ int cmd_main(int argc, const char **argv)
13081308
continue;
13091309
}
13101310
if (skip_prefix(arg, "--timeout=", &v)) {
1311-
timeout = atoi(v);
1311+
if (strtoul_ui(v, 10, &timeout))
1312+
die("invalid timeout '%s', expecting a non-negative integer", v);
13121313
continue;
13131314
}
13141315
if (skip_prefix(arg, "--init-timeout=", &v)) {
1315-
init_timeout = atoi(v);
1316+
if (strtoul_ui(v, 10, &init_timeout))
1317+
die("invalid init-timeout '%s', expecting a non-negative integer", v);
13161318
continue;
13171319
}
13181320
if (skip_prefix(arg, "--max-connections=", &v)) {
1319-
max_connections = atoi(v);
1321+
if (strtol_i(v, 10, &max_connections))
1322+
die("invalid max-connections '%s', expecting an integer", v);
13201323
if (max_connections < 0)
1321-
max_connections = 0; /* unlimited */
1324+
max_connections = 0; /* unlimited */
13221325
continue;
13231326
}
13241327
if (!strcmp(arg, "--strict-paths")) {

imap-send.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,12 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
668668
return RESP_BAD;
669669
}
670670
if (!strcmp("UIDVALIDITY", arg)) {
671-
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
671+
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity) {
672672
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
673673
return RESP_BAD;
674674
}
675675
} else if (!strcmp("UIDNEXT", arg)) {
676-
if (!(arg = next_arg(&s)) || !(imap->uidnext = atoi(arg))) {
676+
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &imap->uidnext) || !imap->uidnext) {
677677
fprintf(stderr, "IMAP error: malformed NEXTUID status\n");
678678
return RESP_BAD;
679679
}
@@ -686,8 +686,8 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
686686
for (; isspace((unsigned char)*p); p++);
687687
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
688688
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
689-
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) ||
690-
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {
689+
if (!(arg = next_arg(&s)) || (strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity) ||
690+
!(arg = next_arg(&s)) || (strtol_i(arg, 10, (int *)cb->ctx) || !cb->ctx)) {
691691
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
692692
return RESP_BAD;
693693
}
@@ -773,7 +773,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
773773
if (!tcmd)
774774
return DRV_OK;
775775
} else {
776-
tag = atoi(arg);
776+
if (strtol_i(arg, 10, &tag)) {
777+
fprintf(stderr, "IMAP error: malformed tag %s\n", arg);
778+
return RESP_BAD;
779+
}
777780
for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next)
778781
if (cmdp->tag == tag)
779782
goto gottag;

merge-ll.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
427427
git_check_attr(istate, path, check);
428428
ll_driver_name = check->items[0].value;
429429
if (check->items[1].value) {
430-
marker_size = atoi(check->items[1].value);
430+
if (strtol_i(check->items[1].value, 10, &marker_size))
431+
die("invalid marker-size '%s', expecting an integer", check->items[1].value);
431432
if (marker_size <= 0)
432433
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
433434
}
@@ -454,7 +455,8 @@ int ll_merge_marker_size(struct index_state *istate, const char *path)
454455
check = attr_check_initl("conflict-marker-size", NULL);
455456
git_check_attr(istate, path, check);
456457
if (check->items[0].value) {
457-
marker_size = atoi(check->items[0].value);
458+
if (strtol_i(check->items[0].value, 10, &marker_size))
459+
die("invalid marker-size '%s', expecting an integer", check->items[0].value);
458460
if (marker_size <= 0)
459461
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
460462
}

t/t5570-git-daemon.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
11
#!/bin/sh
22

3-
test_description='test fetching over git protocol'
3+
test_description='test fetching over git protocol and daemon rejects invalid options'
44
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
55
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
66

77
TEST_PASSES_SANITIZE_LEAK=true
88
. ./test-lib.sh
99

1010
. "$TEST_DIRECTORY"/lib-git-daemon.sh
11+
12+
test_expect_success 'daemon rejects invalid --init-timeout values' '
13+
for arg in "3a" "-3"
14+
do
15+
test_must_fail git daemon --init-timeout="$arg" 2>actual_error &&
16+
test_write_lines "fatal: invalid init-timeout '\''$arg'\'', expecting a non-negative integer" >expected &&
17+
test_cmp actual_error expected || return 1
18+
done
19+
'
20+
21+
test_expect_success 'daemon rejects invalid --timeout values' '
22+
for arg in "3a" "-3"
23+
do
24+
test_must_fail git daemon --timeout="$arg" 2>actual_error &&
25+
test_write_lines "fatal: invalid timeout '\''$arg'\'', expecting a non-negative integer" >expected &&
26+
test_cmp actual_error expected || return 1
27+
done
28+
'
29+
30+
test_expect_success 'daemon rejects invalid --max-connections values' '
31+
test_must_fail git daemon --max-connections=3a 2>actual_error &&
32+
test_write_lines "fatal: invalid max-connections '\''3a'\'', expecting an integer" >expected &&
33+
test_cmp actual_error expected
34+
'
35+
1136
start_git_daemon
1237

1338
check_verbose_connect () {

t/t6406-merge-attr.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ test_expect_success 'retry the merge with longer context' '
118118
grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
119119
'
120120

121+
test_expect_success 'invalid conflict-marker-size 3a' '
122+
echo "text conflict-marker-size=3a" >>.gitattributes &&
123+
test_must_fail git checkout -m text 2>actual_error &&
124+
test_write_lines "fatal: invalid marker-size '\''3a'\'', expecting an integer" >expected &&
125+
test_cmp actual_error expected
126+
'
127+
121128
test_expect_success 'custom merge backend' '
122129
123130
echo "* merge=union" >.gitattributes &&

0 commit comments

Comments
 (0)