summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 88cd621)
raw | patch | inline | side by side (parent: 88cd621)
author | Linus Torvalds <torvalds@osdl.org> | |
Sat, 1 Oct 2005 06:25:23 +0000 (23:25 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 1 Oct 2005 06:52:48 +0000 (23:52 -0700) |
A patch that contains no actual diff, and that doesn't change any
meta-data is bad. It shouldn't be a patch at all, and git-apply shouldn't
just accept it.
This caused a corrupted patch to be silently applied as an empty change in
the kernel, because the corruption ended up making the patch look empty.
An example of such a patch is one that contains the patch header, but
where the initial fragment header (the "@@ -nr,.." line) is missing,
causing us to not parse any fragments.
The real "patch" program will also flag such patches as bad, with the
message
patch: **** Only garbage was found in the patch input.
and we should do likewise.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
meta-data is bad. It shouldn't be a patch at all, and git-apply shouldn't
just accept it.
This caused a corrupted patch to be silently applied as an empty change in
the kernel, because the corruption ended up making the patch look empty.
An example of such a patch is one that contains the patch header, but
where the initial fragment header (the "@@ -nr,.." line) is missing,
causing us to not parse any fragments.
The real "patch" program will also flag such patches as bad, with the
message
patch: **** Only garbage was found in the patch input.
and we should do likewise.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
apply.c | patch | blob | history |
index 964df2db10c22d6ed0b89532e0af8cf9a43e607c..f8862722fdba204d6e15e4d012f8891bcc36475c 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -723,6 +723,16 @@ static int parse_single_patch(char *line, unsigned long size, struct patch *patc
return offset;
}
+static inline int metadata_changes(struct patch *patch)
+{
+ return patch->is_rename > 0 ||
+ patch->is_copy > 0 ||
+ patch->is_new > 0 ||
+ patch->is_delete ||
+ (patch->old_mode && patch->new_mode &&
+ patch->old_mode != patch->new_mode);
+}
+
static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
{
int hdrsize, patchsize;
patchsize = parse_single_patch(buffer + offset + hdrsize, size - offset - hdrsize, patch);
+ if (!patchsize && !metadata_changes(patch))
+ die("patch with only garbage at line %d", linenr);
+
return offset + hdrsize + patchsize;
}