Skip to content

Commit 484e776

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: handle parse_binary() failure
In parse_binary() there is: forward = parse_binary_hunk(&buffer, &size, &status, &used); if (!forward && !status) /* there has to be one hunk (forward hunk) */ return error(_("unrecognized binary patch at line %d"), linenr-1); so parse_binary() can return -1, because that's what error() returns. Also parse_binary_hunk() sets "status" to -1 in case of error and parse_binary() does "if (status) return status;". In this case parse_chunk() should not add -1 to the patchsize it computes. It is better for future libification efforts to make it just return -1. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db354b7 commit 484e776

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

builtin/apply.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,11 @@ static struct fragment *parse_binary_hunk(char **buf_p,
18631863
return NULL;
18641864
}
18651865

1866+
/*
1867+
* Returns:
1868+
* -1 in case of error,
1869+
* the length of the parsed binary patch otherwise
1870+
*/
18661871
static int parse_binary(char *buffer, unsigned long size, struct patch *patch)
18671872
{
18681873
/*
@@ -2008,6 +2013,8 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
20082013
linenr++;
20092014
used = parse_binary(buffer + hd + llen,
20102015
size - hd - llen, patch);
2016+
if (used < 0)
2017+
return -1;
20112018
if (used)
20122019
patchsize = used + llen;
20132020
else

0 commit comments

Comments
 (0)