From: Usman Akinyemi <usmanakinyemi202@xxxxxxxxx> Replaced atoi() with strtol_i() for parsing conflict-marker-size to improve error handling. Invalid values, such as those containing letters now trigger a clear error message. Updated the test to verify invalid input handling. Signed-off-by: Usman Akinyemi <usmanakinyemi202@xxxxxxxxx> --- merge-ll.c | 6 ++++-- t/t6406-merge-attr.sh | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/merge-ll.c b/merge-ll.c index 8e63071922b..52870226816 100644 --- a/merge-ll.c +++ b/merge-ll.c @@ -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; } @@ -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; } diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 9bf95249347..1299b30aeb1 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -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 && -- gitgitgadget