@@ -931,22 +931,19 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
931
931
return find_name (line , NULL , p_value , TERM_TAB );
932
932
933
933
if (orig_name ) {
934
- int len ;
935
- const char * name ;
934
+ int len = strlen (orig_name );
936
935
char * another ;
937
- name = orig_name ;
938
- len = strlen (name );
939
936
if (isnull )
940
- die (_ ("git apply: bad git-diff - expected /dev/null, got %s on line %d" ), name , linenr );
937
+ die (_ ("git apply: bad git-diff - expected /dev/null, got %s on line %d" ),
938
+ orig_name , linenr );
941
939
another = find_name (line , NULL , p_value , TERM_TAB );
942
- if (!another || memcmp (another , name , len + 1 ))
940
+ if (!another || memcmp (another , orig_name , len + 1 ))
943
941
die ((side == DIFF_NEW_NAME ) ?
944
942
_ ("git apply: bad git-diff - inconsistent new filename on line %d" ) :
945
943
_ ("git apply: bad git-diff - inconsistent old filename on line %d" ), linenr );
946
944
free (another );
947
945
return orig_name ;
948
- }
949
- else {
946
+ } else {
950
947
/* expect "/dev/null" */
951
948
if (memcmp ("/dev/null" , line , 9 ) || line [9 ] != '\n' )
952
949
die (_ ("git apply: bad git-diff - expected /dev/null on line %d" ), linenr );
@@ -956,21 +953,15 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
956
953
957
954
static int gitdiff_oldname (const char * line , struct patch * patch )
958
955
{
959
- char * orig = patch -> old_name ;
960
956
patch -> old_name = gitdiff_verify_name (line , patch -> is_new , patch -> old_name ,
961
957
DIFF_OLD_NAME );
962
- if (orig != patch -> old_name )
963
- free (orig );
964
958
return 0 ;
965
959
}
966
960
967
961
static int gitdiff_newname (const char * line , struct patch * patch )
968
962
{
969
- char * orig = patch -> new_name ;
970
963
patch -> new_name = gitdiff_verify_name (line , patch -> is_delete , patch -> new_name ,
971
964
DIFF_NEW_NAME );
972
- if (orig != patch -> new_name )
973
- free (orig );
974
965
return 0 ;
975
966
}
976
967
@@ -1872,6 +1863,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,
1872
1863
return NULL ;
1873
1864
}
1874
1865
1866
+ /*
1867
+ * Returns:
1868
+ * -1 in case of error,
1869
+ * the length of the parsed binary patch otherwise
1870
+ */
1875
1871
static int parse_binary (char * buffer , unsigned long size , struct patch * patch )
1876
1872
{
1877
1873
/*
@@ -2017,6 +2013,8 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
2017
2013
linenr ++ ;
2018
2014
used = parse_binary (buffer + hd + llen ,
2019
2015
size - hd - llen , patch );
2016
+ if (used < 0 )
2017
+ return -1 ;
2020
2018
if (used )
2021
2019
patchsize = used + llen ;
2022
2020
else
@@ -4373,8 +4371,10 @@ static int apply_patch(int fd, const char *filename, int options)
4373
4371
patch -> inaccurate_eof = !!(options & INACCURATE_EOF );
4374
4372
patch -> recount = !!(options & RECOUNT );
4375
4373
nr = parse_chunk (buf .buf + offset , buf .len - offset , patch );
4376
- if (nr < 0 )
4374
+ if (nr < 0 ) {
4375
+ free_patch (patch );
4377
4376
break ;
4377
+ }
4378
4378
if (apply_in_reverse )
4379
4379
reverse_patches (patch );
4380
4380
if (use_patch (patch )) {
0 commit comments