summaryrefslogtreecommitdiff
path: root/src/patch_parse.c
diff options
context:
space:
mode:
authorGregory Herrero <gregory.herrero@oracle.com>2019-11-07 14:13:14 +0100
committerGregory Herrero <gregory.herrero@oracle.com>2019-11-19 09:33:12 +0100
commit048e94adbba3c21b9ad739640cce11a8b387df48 (patch)
tree73c8ff28cb3dd6640cebf3acbda6956ceabd6ca1 /src/patch_parse.c
parentb921964b25c14c8dfeb26d1a5efedb28ee9e7284 (diff)
downloadlibgit2-048e94adbba3c21b9ad739640cce11a8b387df48.tar.gz
patch_parse: correct parsing of patch containing not shown binary data.
When not shown binary data is added or removed in a patch, patch parser is currently returning 'error -1 - corrupt git binary header at line 4'. Fix it by correctly handling case where binary data is added/removed. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
Diffstat (limited to 'src/patch_parse.c')
-rw-r--r--src/patch_parse.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index e4031f11d..87c4b0241 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -231,9 +231,9 @@ static int parse_header_git_deletedfilemode(
git_patch_parsed *patch,
git_patch_parse_ctx *ctx)
{
- git__free((char *)patch->base.delta->old_file.path);
+ git__free((char *)patch->base.delta->new_file.path);
- patch->base.delta->old_file.path = NULL;
+ patch->base.delta->new_file.path = NULL;
patch->base.delta->status = GIT_DELTA_DELETED;
patch->base.delta->nfiles = 1;
@@ -244,9 +244,9 @@ static int parse_header_git_newfilemode(
git_patch_parsed *patch,
git_patch_parse_ctx *ctx)
{
- git__free((char *)patch->base.delta->new_file.path);
+ git__free((char *)patch->base.delta->old_file.path);
- patch->base.delta->new_file.path = NULL;
+ patch->base.delta->old_file.path = NULL;
patch->base.delta->status = GIT_DELTA_ADDED;
patch->base.delta->nfiles = 1;
@@ -884,6 +884,11 @@ static int parse_patch_binary_nodata(
if (!old || !new)
return git_parse_err("corrupt binary data without paths at line %"PRIuZ, ctx->parse_ctx.line_num);
+ if (patch->base.delta->status == GIT_DELTA_ADDED)
+ old = "/dev/null";
+ else if (patch->base.delta->status == GIT_DELTA_DELETED)
+ new = "/dev/null";
+
if (git_parse_advance_expected_str(&ctx->parse_ctx, "Binary files ") < 0 ||
git_parse_advance_expected_str(&ctx->parse_ctx, old) < 0 ||
git_parse_advance_expected_str(&ctx->parse_ctx, " and ") < 0 ||