apply: reject corrupt "diff --git" headers
Get series with b4
b4 am [email protected]Versions newest first
- v3 Latest3 patches 4 repliesIn review
Changes in v3 from the cover letter
- Added 1/3, which frees patch->def_name before setting it, as Siddharth suggested. It brings back the test for an empty "diff --git" line followed by another one, which v2 dropped.
- 2/3 is unchanged, apart from where its tests sit in the file.
- 3/3 names the "---" or "+++" line in the error, instead of the file name, which was "dev/null" for "/dev/null", as Siddharth suggested.
- Fixed a broken line in the 3/3 commit message.
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | apply: free the old def_name in parse_git_diff_header()apply.c t/ | +19 | 4 replies | |
| 2/3 | apply: reject a patch after an empty "diff --git" lineapply.c t/ | +98 | 0 replies | |
| 3/3 | apply: reject new and deleted files that have both namesapply.c t/ | +49 | 0 replies |
Reviews trailers per patch
None of the 3 patches has a Reviewed-by or Acked-by.
| Patch | Phillip Wood | Siddharth Asthana |
|---|---|---|
| 1/3 | ||
| 2/3 | Helped-by | |
| 3/3 | Helped-by |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [Outreachy PATCH v3 0/3] apply: reject corrupt "diff --git" headers
"git apply --check" dies on an assertion in check_preimage() for some patches with a broken "diff --git" header. This series reports these patches as errors instead.
1/3 fixes a leak in parse_git_diff_header().
2/3 rejects a patch that is read under an empty "diff --git" line, like a "diff --git" line with a blank line after it.
3/3 rejects a new file with a "---" line before "new file mode", and a deleted file with a "+++" line before "deleted file mode".
Changes since v2:
- Added 1/3, which frees patch->def_name before setting it, as Siddharth suggested. It brings back the test for an empty "diff --git" line followed by another one, which v2 dropped.
- 2/3 is unchanged, apart from where its tests sit in the file.
- 3/3 names the "---" or "+++" line in the error, instead of the file name, which was "dev/null" for "/dev/null", as Siddharth suggested.
- Fixed a broken line in the 3/3 commit message.
Tanga Joris (3):
apply: free the old def_name in parse_git_diff_header()
apply: reject a patch after an empty "diff --git" line
apply: reject new and deleted files that have both names
apply.c | 32 ++++++++- t/t4133-apply-filenames.sh | 135 +++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 1 deletion(-)
Range-diff against v2:
-: ---------- > 1: 8136f837a9 apply: free the old def_name in parse_git_diff_header() 1: 3b802e3053 ! 2: 048574a48f apply: reject a patch after an empty "diff --git" line
@@ t/t4133-apply-filenames.sh: test_expect_success 'apply diff with old filename mi
+ reject_empty_git_header later_line.diff 3
+'
+
- test_done
+ test_expect_success 'ignore an empty "diff --git" line before a git patch' '
+ test_when_finished "rm -f g" &&
+ echo 1 >g &&
2: f2d40ed931 ! 3: b3da07db98 apply: reject new and deleted files that have both names
@@ Commit message
lines, 2017-06-27) made apply report other conflicting header lines,
instead of leaving them to an assertion. Do the same here. After the
header is read, reject a new file that has an old name. Reject a
- deleted file that has a new name too.
+ deleted file that has a new name too. The error names the "---" or
+ "+++" line that came before the mode line. It does not print the
+ name, because for "/dev/null" that would be "dev/null".
Git always writes the mode line first, so patches made by Git are not
- affected. A patch with
- "+++ /dev/null" before "deleted file mode" used to apply without -R.
- It is now rejected too.
+ affected. A patch with "+++ /dev/null" before "deleted file mode" used
+ to apply without -R. It is now rejected too.
+ Helped-by: Siddharth Asthana <[email protected]>
Signed-off-by: Tanga Joris <[email protected]>
## apply.c ##
@@ apply.c: int parse_git_diff_header(struct strbuf *root,
}
+ if (patch->is_new > 0 && patch->old_name) {
+ if (patch_input_file)
-+ error(_("git diff header for new file %s names an old file %s at %s:%d"),
-+ patch->new_name, patch->old_name,
-+ patch_input_file, *linenr);
++ error(_("git diff header has \"---\" before \"new file mode\" at %s:%d"),
++ patch_input_file, patch->extension_linenr);
+ else
-+ error(_("git diff header for new file %s names an old file %s (line %d)"),
-+ patch->new_name, patch->old_name, *linenr);
++ error(_("git diff header has \"---\" before \"new file mode\" (line %d)"),
++ patch->extension_linenr);
+ return -128;
+ }
+ if (patch->is_delete > 0 && patch->new_name) {
+ if (patch_input_file)
-+ error(_("git diff header for deleted file %s names a new file %s at %s:%d"),
-+ patch->old_name, patch->new_name,
-+ patch_input_file, *linenr);
++ error(_("git diff header has \"+++\" before \"deleted file mode\" at %s:%d"),
++ patch_input_file, patch->extension_linenr);
+ else
-+ error(_("git diff header for deleted file %s names a new file %s (line %d)"),
-+ patch->old_name, patch->new_name, *linenr);
++ error(_("git diff header has \"+++\" before \"deleted file mode\" (line %d)"),
++ patch->extension_linenr);
+ return -128;
+ }
patch->is_toplevel_relative = 1;
@@ apply.c: int parse_git_diff_header(struct strbuf *root,
}
## t/t4133-apply-filenames.sh ##
-@@ t/t4133-apply-filenames.sh: test_expect_success 'name the empty "diff --git" line in the error' '
- reject_empty_git_header later_line.diff 3
+@@ t/t4133-apply-filenames.sh: test_expect_success 'ignore an empty "diff --git" line before a git patch' '
+ test_cmp expect g
'
+for old in /dev/null a/f
@@ t/t4133-apply-filenames.sh: test_expect_success 'name the empty "diff --git" lin
+ +1
+ EOF
+ test_must_fail git apply --check old_before_new.diff 2>err &&
-+ test_grep "header for new file f names an old file" err
++ test_grep "has \"---\" before \"new file mode\" at old_before_new.diff:4" err
+ '
+done
+
@@ t/t4133-apply-filenames.sh: test_expect_success 'name the empty "diff --git" lin
+ -1
+ EOF
+ test_must_fail git apply --check new_before_delete.diff 2>err &&
-+ test_grep "header for deleted file f names a new file" err &&
++ test_grep "has \"+++\" before \"deleted file mode\" at new_before_delete.diff:4" err &&
+ test_must_fail git apply --check -R new_before_delete.diff 2>err &&
-+ test_grep "header for deleted file f names a new file" err
++ test_grep "has \"+++\" before \"deleted file mode\" at new_before_delete.diff:4" err
+'
+
test_donebase-commit: a018953688f1b10bddf91bff8747068f5f4746a4
Signature · 1 line
2.43.0