Skip to content

Commit

Permalink
Merge branch 'ua/atoi' into seen
Browse files Browse the repository at this point in the history
* 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()
  • Loading branch information
ttaylorr committed Oct 18, 2024
2 parents b8ce139 + ef90600 commit 63b77ed
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
11 changes: 7 additions & 4 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1308,17 +1308,20 @@ int cmd_main(int argc, const char **argv)
continue;
}
if (skip_prefix(arg, "--timeout=", &v)) {
timeout = atoi(v);
if (strtoul_ui(v, 10, &timeout))
die("invalid timeout '%s', expecting a non-negative integer", v);
continue;
}
if (skip_prefix(arg, "--init-timeout=", &v)) {
init_timeout = atoi(v);
if (strtoul_ui(v, 10, &init_timeout))
die("invalid init-timeout '%s', expecting a non-negative integer", v);
continue;
}
if (skip_prefix(arg, "--max-connections=", &v)) {
max_connections = atoi(v);
if (strtol_i(v, 10, &max_connections))
die("invalid max-connections '%s', expecting an integer", v);
if (max_connections < 0)
max_connections = 0; /* unlimited */
max_connections = 0; /* unlimited */
continue;
}
if (!strcmp(arg, "--strict-paths")) {
Expand Down
13 changes: 8 additions & 5 deletions imap-send.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,12 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
return RESP_BAD;
}
if (!strcmp("UIDVALIDITY", arg)) {
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity) {
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
return RESP_BAD;
}
} else if (!strcmp("UIDNEXT", arg)) {
if (!(arg = next_arg(&s)) || !(imap->uidnext = atoi(arg))) {
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &imap->uidnext) || !imap->uidnext) {
fprintf(stderr, "IMAP error: malformed NEXTUID status\n");
return RESP_BAD;
}
Expand All @@ -686,8 +686,8 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
for (; isspace((unsigned char)*p); p++);
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) ||
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {
if (!(arg = next_arg(&s)) || (strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity) ||
!(arg = next_arg(&s)) || (strtol_i(arg, 10, (int *)cb->ctx) || !cb->ctx)) {
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
return RESP_BAD;
}
Expand Down Expand Up @@ -773,7 +773,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
if (!tcmd)
return DRV_OK;
} else {
tag = atoi(arg);
if (strtol_i(arg, 10, &tag)) {
fprintf(stderr, "IMAP error: malformed tag %s\n", arg);
return RESP_BAD;
}
for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next)
if (cmdp->tag == tag)
goto gottag;
Expand Down
6 changes: 4 additions & 2 deletions merge-ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
git_check_attr(istate, path, check);
ll_driver_name = check->items[0].value;
if (check->items[1].value) {
marker_size = atoi(check->items[1].value);
if (strtol_i(check->items[1].value, 10, &marker_size))
die("invalid marker-size '%s', expecting an integer", check->items[1].value);
if (marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
}
Expand All @@ -454,7 +455,8 @@ int ll_merge_marker_size(struct index_state *istate, const char *path)
check = attr_check_initl("conflict-marker-size", NULL);
git_check_attr(istate, path, check);
if (check->items[0].value) {
marker_size = atoi(check->items[0].value);
if (strtol_i(check->items[0].value, 10, &marker_size))
die("invalid marker-size '%s', expecting an integer", check->items[0].value);
if (marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
}
Expand Down
27 changes: 26 additions & 1 deletion t/t5570-git-daemon.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
#!/bin/sh

test_description='test fetching over git protocol'
test_description='test fetching over git protocol and daemon rejects invalid options'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

. "$TEST_DIRECTORY"/lib-git-daemon.sh

test_expect_success 'daemon rejects invalid --init-timeout values' '
for arg in "3a" "-3"
do
test_must_fail git daemon --init-timeout="$arg" 2>actual_error &&
test_write_lines "fatal: invalid init-timeout '\''$arg'\'', expecting a non-negative integer" >expected &&
test_cmp actual_error expected || return 1
done
'

test_expect_success 'daemon rejects invalid --timeout values' '
for arg in "3a" "-3"
do
test_must_fail git daemon --timeout="$arg" 2>actual_error &&
test_write_lines "fatal: invalid timeout '\''$arg'\'', expecting a non-negative integer" >expected &&
test_cmp actual_error expected || return 1
done
'

test_expect_success 'daemon rejects invalid --max-connections values' '
test_must_fail git daemon --max-connections=3a 2>actual_error &&
test_write_lines "fatal: invalid max-connections '\''3a'\'', expecting an integer" >expected &&
test_cmp actual_error expected
'

start_git_daemon

check_verbose_connect () {
Expand Down
7 changes: 7 additions & 0 deletions t/t6406-merge-attr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ test_expect_success 'retry the merge with longer context' '
grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
'

test_expect_success 'invalid conflict-marker-size 3a' '
echo "text conflict-marker-size=3a" >>.gitattributes &&
test_must_fail git checkout -m text 2>actual_error &&
test_write_lines "fatal: invalid marker-size '\''3a'\'', expecting an integer" >expected &&
test_cmp actual_error expected
'

test_expect_success 'custom merge backend' '
echo "* merge=union" >.gitattributes &&
Expand Down

0 comments on commit 63b77ed

Please sign in to comment.