Merge branch 'ua/atoi'
Replace various calls to atoi() with strtol_i() and strtoul_ui(), and add improved error handling. * 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()
This commit is contained in:
12
daemon.c
12
daemon.c
@@ -4,6 +4,7 @@
|
|||||||
#include "abspath.h"
|
#include "abspath.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
#include "gettext.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "pkt-line.h"
|
#include "pkt-line.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
@@ -1308,17 +1309,20 @@ int cmd_main(int argc, const char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (skip_prefix(arg, "--timeout=", &v)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (skip_prefix(arg, "--init-timeout=", &v)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (skip_prefix(arg, "--max-connections=", &v)) {
|
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)
|
if (max_connections < 0)
|
||||||
max_connections = 0; /* unlimited */
|
max_connections = 0; /* unlimited */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--strict-paths")) {
|
if (!strcmp(arg, "--strict-paths")) {
|
||||||
|
|||||||
13
imap-send.c
13
imap-send.c
@@ -668,12 +668,12 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
|
|||||||
return RESP_BAD;
|
return RESP_BAD;
|
||||||
}
|
}
|
||||||
if (!strcmp("UIDVALIDITY", arg)) {
|
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");
|
fprintf(stderr, "IMAP error: malformed UIDVALIDITY status\n");
|
||||||
return RESP_BAD;
|
return RESP_BAD;
|
||||||
}
|
}
|
||||||
} else if (!strcmp("UIDNEXT", arg)) {
|
} 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");
|
fprintf(stderr, "IMAP error: malformed NEXTUID status\n");
|
||||||
return RESP_BAD;
|
return RESP_BAD;
|
||||||
}
|
}
|
||||||
@@ -686,8 +686,8 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,
|
|||||||
for (; isspace((unsigned char)*p); p++);
|
for (; isspace((unsigned char)*p); p++);
|
||||||
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
|
fprintf(stderr, "*** IMAP ALERT *** %s\n", p);
|
||||||
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
|
} else if (cb && cb->ctx && !strcmp("APPENDUID", arg)) {
|
||||||
if (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) ||
|
if (!(arg = next_arg(&s)) || strtol_i(arg, 10, &ctx->uidvalidity) || !ctx->uidvalidity ||
|
||||||
!(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {
|
!(arg = next_arg(&s)) || strtol_i(arg, 10, (int *)cb->ctx) || !cb->ctx) {
|
||||||
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
|
fprintf(stderr, "IMAP error: malformed APPENDUID status\n");
|
||||||
return RESP_BAD;
|
return RESP_BAD;
|
||||||
}
|
}
|
||||||
@@ -773,7 +773,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
|
|||||||
if (!tcmd)
|
if (!tcmd)
|
||||||
return DRV_OK;
|
return DRV_OK;
|
||||||
} else {
|
} 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)
|
for (pcmdp = &imap->in_progress; (cmdp = *pcmdp); pcmdp = &cmdp->next)
|
||||||
if (cmdp->tag == tag)
|
if (cmdp->tag == tag)
|
||||||
goto gottag;
|
goto gottag;
|
||||||
|
|||||||
11
merge-ll.c
11
merge-ll.c
@@ -15,6 +15,7 @@
|
|||||||
#include "merge-ll.h"
|
#include "merge-ll.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
struct ll_merge_driver;
|
struct ll_merge_driver;
|
||||||
|
|
||||||
@@ -427,7 +428,10 @@ enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
|
|||||||
git_check_attr(istate, path, check);
|
git_check_attr(istate, path, check);
|
||||||
ll_driver_name = check->items[0].value;
|
ll_driver_name = check->items[0].value;
|
||||||
if (check->items[1].value) {
|
if (check->items[1].value) {
|
||||||
marker_size = atoi(check->items[1].value);
|
if (strtol_i(check->items[1].value, 10, &marker_size)) {
|
||||||
|
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
|
||||||
|
warning(_("invalid marker-size '%s', expecting an integer"), check->items[1].value);
|
||||||
|
}
|
||||||
if (marker_size <= 0)
|
if (marker_size <= 0)
|
||||||
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
|
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
|
||||||
}
|
}
|
||||||
@@ -454,7 +458,10 @@ int ll_merge_marker_size(struct index_state *istate, const char *path)
|
|||||||
check = attr_check_initl("conflict-marker-size", NULL);
|
check = attr_check_initl("conflict-marker-size", NULL);
|
||||||
git_check_attr(istate, path, check);
|
git_check_attr(istate, path, check);
|
||||||
if (check->items[0].value) {
|
if (check->items[0].value) {
|
||||||
marker_size = atoi(check->items[0].value);
|
if (strtol_i(check->items[0].value, 10, &marker_size)) {
|
||||||
|
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
|
||||||
|
warning(_("invalid marker-size '%s', expecting an integer"), check->items[0].value);
|
||||||
|
}
|
||||||
if (marker_size <= 0)
|
if (marker_size <= 0)
|
||||||
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
|
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,31 @@ TEST_PASSES_SANITIZE_LEAK=true
|
|||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
. "$TEST_DIRECTORY"/lib-git-daemon.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>err &&
|
||||||
|
test_grep "fatal: invalid init-timeout ${SQ}$arg${SQ}, expecting a non-negative integer" err ||
|
||||||
|
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>err &&
|
||||||
|
test_grep "fatal: invalid timeout ${SQ}$arg${SQ}, expecting a non-negative integer" err ||
|
||||||
|
return 1
|
||||||
|
done
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'daemon rejects invalid --max-connections values' '
|
||||||
|
arg='3a' &&
|
||||||
|
test_must_fail git daemon --max-connections=3a 2>err &&
|
||||||
|
test_grep "fatal: invalid max-connections ${SQ}$arg${SQ}, expecting an integer" err
|
||||||
|
'
|
||||||
|
|
||||||
start_git_daemon
|
start_git_daemon
|
||||||
|
|
||||||
check_verbose_connect () {
|
check_verbose_connect () {
|
||||||
|
|||||||
@@ -118,6 +118,14 @@ test_expect_success 'retry the merge with longer context' '
|
|||||||
grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
|
grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'invalid conflict-marker-size 3a' '
|
||||||
|
cp .gitattributes .gitattributes.bak &&
|
||||||
|
echo "text conflict-marker-size=3a" >>.gitattributes &&
|
||||||
|
test_when_finished "mv .gitattributes.bak .gitattributes" &&
|
||||||
|
git checkout -m text 2>err &&
|
||||||
|
test_grep "warning: invalid marker-size ${SQ}3a${SQ}, expecting an integer" err
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'custom merge backend' '
|
test_expect_success 'custom merge backend' '
|
||||||
|
|
||||||
echo "* merge=union" >.gitattributes &&
|
echo "* merge=union" >.gitattributes &&
|
||||||
|
|||||||
Reference in New Issue
Block a user