Skip to content

Commit 7bbdcbd

Browse files
authored
patch: improve validation of normal diffs (2) (briandfoy#955)
* In a Normal diff the commands c and d operate on a line number range written as x,y * The range 2,1 is not valid * Reject a diff if a backwards range is seen to avoid incorrectly processing a file, then reporting "successful patch" * I found this when testing against the GNU version
1 parent 71d1681 commit 7bbdcbd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

bin/patch

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ while (<PATCH>) {
210210
last;
211211
}
212212
$i_end = $i_start unless defined $i_end; # for input "XcY,Z" and "XdY,Z"
213+
214+
if ($cmd ne 'a' && $i_start > $i_end) { # bad range "2,1c" and "2,1d"
215+
my $input = $_;
216+
chomp $input;
217+
$patch->note("Malformed input at line $.: $input\n");
218+
$patch->reject($range);
219+
last;
220+
}
213221
my (@d_hunk, @a_hunk);
214222
my $d_re = qr/^$space< /;
215223
my $a_re = qr/^$space> /;

0 commit comments

Comments
 (0)