Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2021-02-28 14:22:47 +0300
committerJunio C Hamano <gitster@pobox.com>2021-03-12 00:22:44 +0300
commit96099726ddb00b45135964220ce56468ba9fe184 (patch)
tree67511a24e20bf148d232a8595719cb8bf48d4077 /archive.c
parent273c9901c2ebfb2dae0c52de912bf3f57be19aac (diff)
archive: expand only a single %(describe) per archive
Every %(describe) placeholder in $Format:...$ strings in files with the attribute export-subst is expanded by calling git describe. This can potentially result in a lot of such calls per archive. That's OK for local repositories under control of the user of git archive, but could be a problem for hosted repositories. Expand only a single %(describe) placeholder per archive for now to avoid denial-of-service attacks. We can make this limit configurable later if needed, but let's start out simple. Reported-by: Jeff King <peff@peff.net> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/archive.c b/archive.c
index 5919d9e505..2dd2236ae0 100644
--- a/archive.c
+++ b/archive.c
@@ -37,13 +37,10 @@ void init_archivers(void)
static void format_subst(const struct commit *commit,
const char *src, size_t len,
- struct strbuf *buf)
+ struct strbuf *buf, struct pretty_print_context *ctx)
{
char *to_free = NULL;
struct strbuf fmt = STRBUF_INIT;
- struct pretty_print_context ctx = {0};
- ctx.date_mode.type = DATE_NORMAL;
- ctx.abbrev = DEFAULT_ABBREV;
if (src == buf->buf)
to_free = strbuf_detach(buf, NULL);
@@ -61,7 +58,7 @@ static void format_subst(const struct commit *commit,
strbuf_add(&fmt, b + 8, c - b - 8);
strbuf_add(buf, src, b - src);
- format_commit_message(commit, fmt.buf, buf, &ctx);
+ format_commit_message(commit, fmt.buf, buf, ctx);
len -= c + 1 - src;
src = c + 1;
}
@@ -94,7 +91,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
convert_to_working_tree(args->repo->index, path, buf.buf, buf.len, &buf, &meta);
if (commit)
- format_subst(commit, buf.buf, buf.len, &buf);
+ format_subst(commit, buf.buf, buf.len, &buf, args->pretty_ctx);
buffer = strbuf_detach(&buf, &size);
*sizep = size;
}
@@ -633,12 +630,19 @@ int write_archive(int argc, const char **argv, const char *prefix,
const char *name_hint, int remote)
{
const struct archiver *ar = NULL;
+ struct pretty_print_describe_status describe_status = {0};
+ struct pretty_print_context ctx = {0};
struct archiver_args args;
int rc;
git_config_get_bool("uploadarchive.allowunreachable", &remote_allow_unreachable);
git_config(git_default_config, NULL);
+ describe_status.max_invocations = 1;
+ ctx.date_mode.type = DATE_NORMAL;
+ ctx.abbrev = DEFAULT_ABBREV;
+ ctx.describe_status = &describe_status;
+ args.pretty_ctx = &ctx;
args.repo = repo;
args.prefix = prefix;
string_list_init(&args.extra_files, 1);