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

git.zx2c4.com/cgit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-05-18 00:50:53 +0300
committerJason A. Donenfeld <Jason@zx2c4.com>2022-12-19 17:09:34 +0300
commitb9ff119549f6018adc54c8447ad87943c6bcb55e (patch)
treeb64a6420cba0cafeb4597530f986686c8707eb12
parentbb02e24ec23d7f1893fc746c8199e88ab849cf86 (diff)
shared: fix bad free in cgit_diff_tree
Since git commit 244c27242f44e6b88e3a381c90bde08d134c274b, > diff.[ch]: have diff_free() call clear_pathspec(opts.pathspec) calling diff_flush calls free(3) on opts.pathspec.items, so it can't be a pointer to a stack variable. Signed-off-by: Christian Hesse <mail@eworm.de>
-rw-r--r--shared.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/shared.c b/shared.c
index 8115469..0bceb98 100644
--- a/shared.c
+++ b/shared.c
@@ -341,9 +341,8 @@ void cgit_diff_tree(const struct object_id *old_oid,
filepair_fn fn, const char *prefix, int ignorews)
{
struct diff_options opt;
- struct pathspec_item item;
+ struct pathspec_item *item;
- memset(&item, 0, sizeof(item));
diff_setup(&opt);
opt.output_format = DIFF_FORMAT_CALLBACK;
opt.detect_rename = 1;
@@ -354,10 +353,11 @@ void cgit_diff_tree(const struct object_id *old_oid,
opt.format_callback = cgit_diff_tree_cb;
opt.format_callback_data = fn;
if (prefix) {
- item.match = xstrdup(prefix);
- item.len = strlen(prefix);
+ item = xcalloc(1, sizeof(*item));
+ item->match = xstrdup(prefix);
+ item->len = strlen(prefix);
opt.pathspec.nr = 1;
- opt.pathspec.items = &item;
+ opt.pathspec.items = item;
}
diff_setup_done(&opt);
@@ -367,8 +367,6 @@ void cgit_diff_tree(const struct object_id *old_oid,
diff_root_tree_oid(new_oid, "", &opt);
diffcore_std(&opt);
diff_flush(&opt);
-
- free(item.match);
}
void cgit_diff_commit(struct commit *commit, filepair_fn fn, const char *prefix)