aboutsummaryrefslogtreecommitdiffstats
path: root/setup.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-06-12 13:37:16 -0700
committerJunio C Hamano <gitster@pobox.com>2024-06-12 13:37:16 -0700
commitb8bdb2f2835c9877120651cc9f22eaca6f8f66a8 (patch)
tree6dfc65108212fcea65aafa69e1b82e5bb3e13bb5 /setup.c
parent22cf18fd9ede79bdfe5ac93e09986a64052e5781 (diff)
parent313eec177ad010048b399d6fd14de871b517f7e3 (diff)
downloadgit-b8bdb2f2835c9877120651cc9f22eaca6f8f66a8.tar.gz
Merge branch 'jc/safe-directory-leading-path'
The safe.directory configuration knob has been updated to optionally allow leading path matches. * jc/safe-directory-leading-path: safe.directory: allow "lead/ing/path/*" match
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/setup.c b/setup.c
index e47946d0e7..e112545f71 100644
--- a/setup.c
+++ b/setup.c
@@ -1230,13 +1230,20 @@ static int safe_directory_cb(const char *key, const char *value,
} else if (!strcmp(value, "*")) {
data->is_safe = 1;
} else {
- char *interpolated = NULL;
-
- if (!git_config_pathname(&interpolated, key, value) &&
- !fspathcmp(data->path, interpolated ? interpolated : value))
- data->is_safe = 1;
-
- free(interpolated);
+ char *allowed = NULL;
+
+ if (!git_config_pathname(&allowed, key, value)) {
+ const char *check = allowed ? allowed : value;
+ if (ends_with(check, "/*")) {
+ size_t len = strlen(check);
+ if (!fspathncmp(check, data->path, len - 1))
+ data->is_safe = 1;
+ } else if (!fspathcmp(data->path, check)) {
+ data->is_safe = 1;
+ }
+ }
+ if (allowed != value)
+ free(allowed);
}
return 0;