From c7290109b1048d062c93ea0dfd3b6512beb56249 Mon Sep 17 00:00:00 2001 From: Phillip Wood Date: Wed, 15 Nov 2023 20:37:40 +0000 Subject: [PATCH] refs: ensure multi-level refnames begin with "refs/" Signed-off-by: Phillip Wood --- refs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/refs.c b/refs.c index fcae5dddc60506..3997da6f829579 100644 --- a/refs.c +++ b/refs.c @@ -263,6 +263,15 @@ static int check_or_sanitize_refname(const char *refname, int flags, return -1; } + if (!(flags & REFNAME_ALLOW_ONELEVEL) && + !skip_prefix(refname, "refs/", &refname)) { + return -1; + } else if (sanitized) { + if (sanitized->len) + strbuf_complete(sanitized, '/'); + strbuf_addstr(sanitized, "refs/"); + } + while (1) { if (sanitized && sanitized->len) strbuf_complete(sanitized, '/');