From: Junio C Hamano Date: Wed, 12 Jun 2024 20:37:16 +0000 (-0700) Subject: Merge branch 'jc/safe-directory-leading-path' X-Git-Tag: v2.46.0-rc0~64 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b8bdb2f2835c9877120651cc9f22eaca6f8f66a8;p=thirdparty%2Fgit.git 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 --- b8bdb2f2835c9877120651cc9f22eaca6f8f66a8 diff --cc setup.c index e47946d0e7,4c5de0960b..e112545f71 --- a/setup.c +++ b/setup.c @@@ -1230,13 -1176,21 +1230,20 @@@ static int safe_directory_cb(const cha } 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); - const char *allowed = NULL; ++ char *allowed = NULL; + + if (!git_config_pathname(&allowed, key, value)) { - if (!allowed) - allowed = value; - if (ends_with(allowed, "/*")) { - size_t len = strlen(allowed); - if (!fspathncmp(allowed, data->path, len - 1)) ++ 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, allowed)) { ++ } else if (!fspathcmp(data->path, check)) { + data->is_safe = 1; + } + } + if (allowed != value) - free((char *)allowed); ++ free(allowed); } return 0;