debian: apply security fixes from 2.24.1
[git/debian.git] / debian / patches / 0005-fast-import-delay-creating-leading-directories-for-ex.diff
blob3bab2660e594ae230b385a38c83bc1ae3ab1be0f
1 From 947fde73faf5fcab808c1449be1a8001e77e9cc8 Mon Sep 17 00:00:00 2001
2 From: Jeff King <peff@peff.net>
3 Date: Thu, 29 Aug 2019 13:33:48 -0400
4 Subject: fast-import: delay creating leading directories for export-marks
6 When we parse the --export-marks option, we don't immediately open the
7 file, but we do create any leading directories. This can be especially
8 confusing when a command-line option overrides an in-stream one, in
9 which case we'd create the leading directory for the in-stream file,
10 even though we never actually write the file.
12 Let's instead create the directories just before opening the file, which
13 means we'll create only useful directories. Note that this could change
14 the handling of relative paths if we chdir() in between, but we don't
15 actually do so; the only permanent chdir is from setup_git_directory()
16 which runs before either code path (potentially we should take the
17 pre-setup dir into account to avoid surprising the user, but that's an
18 orthogonal change).
20 The test just adapts the existing "override" test to use paths with
21 leading directories. This checks both that the correct directory is
22 created (which worked before but was not tested), and that the
23 overridden one is not (our new fix here).
25 While we're here, let's also check the error result of
26 safe_create_leading_directories(). We'd presumably notice any failure
27 immediately after when we try to open the file itself, but we can give a
28 more specific error message in this case.
30 Signed-off-by: Jeff King <peff@peff.net>
31 (cherry picked from commit 019683025f1b14d7cb671312ab01f7330e9b33e7)
32 Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
33 ---
34 fast-import.c | 7 ++++++-
35 t/t9300-fast-import.sh | 13 +++++++++++--
36 2 files changed, 17 insertions(+), 3 deletions(-)
38 diff --git a/fast-import.c b/fast-import.c
39 index 2c89ddb453..9cfc1386a3 100644
40 --- a/fast-import.c
41 +++ b/fast-import.c
42 @@ -1682,6 +1682,12 @@ static void dump_marks(void)
43 if (!export_marks_file || (import_marks_file && !import_marks_file_done))
44 return;
46 + if (safe_create_leading_directories_const(export_marks_file)) {
47 + failure |= error_errno("unable to create leading directories of %s",
48 + export_marks_file);
49 + return;
50 + }
52 if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
53 failure |= error_errno("Unable to write marks file %s",
54 export_marks_file);
55 @@ -3186,7 +3192,6 @@ static void option_active_branches(const char *branches)
56 static void option_export_marks(const char *marks)
58 export_marks_file = make_fast_import_path(marks);
59 - safe_create_leading_directories_const(export_marks_file);
62 static void option_cat_blob_fd(const char *fd)
63 diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
64 index e6a0343c80..14df3b0475 100755
65 --- a/t/t9300-fast-import.sh
66 +++ b/t/t9300-fast-import.sh
67 @@ -2169,8 +2169,17 @@ test_expect_success 'R: export-marks feature results in a marks file being creat
70 test_expect_success 'R: export-marks options can be overridden by commandline options' '
71 - git fast-import --export-marks=other.marks <input &&
72 - grep :1 other.marks
73 + cat >input <<-\EOF &&
74 + feature export-marks=feature-sub/git.marks
75 + blob
76 + mark :1
77 + data 3
78 + hi
80 + EOF
81 + git fast-import --export-marks=cmdline-sub/other.marks <input &&
82 + grep :1 cmdline-sub/other.marks &&
83 + test_path_is_missing feature-sub
86 test_expect_success 'R: catch typo in marks file name' '
87 --
88 2.24.0.393.g34dc348eaf