summaryrefslogtreecommitdiffstats
path: root/merge-ll.c
diff options
context:
space:
mode:
authorUsman Akinyemi <usmanakinyemi202@gmail.com>2024-10-24 02:24:57 +0200
committerTaylor Blau <me@ttaylorr.com>2024-10-24 20:03:44 +0200
commite36f009e69b68a82f216f9633f99198421a67f12 (patch)
treea933bdc9a0c9ac0186da758f2a0e6d52982ed36d /merge-ll.c
parentdaemon: replace atoi() with strtoul_ui() and strtol_i() (diff)
downloadgit-e36f009e69b68a82f216f9633f99198421a67f12.tar.xz
git-e36f009e69b68a82f216f9633f99198421a67f12.zip
merge: replace atoi() with strtol_i() for marker size validation
Replace 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. Update the test to verify invalid input handling. Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'merge-ll.c')
-rw-r--r--merge-ll.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/merge-ll.c b/merge-ll.c
index 8e63071922..62fc625552 100644
--- a/merge-ll.c
+++ b/merge-ll.c
@@ -15,6 +15,7 @@
#include "merge-ll.h"
#include "quote.h"
#include "strbuf.h"
+#include "gettext.h"
struct ll_merge_driver;
@@ -427,7 +428,10 @@ 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)) {
+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
+ warning(_("invalid marker-size '%s', expecting an integer"), check->items[1].value);
+ }
if (marker_size <= 0)
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);
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)) {
+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
+ warning(_("invalid marker-size '%s', expecting an integer"), check->items[0].value);
+ }
if (marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
}