diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2019-11-06 06:04:37 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-06 06:04:37 -0500 |
| commit | a3d8a43755dae7292857a0afa847601d2a85a1af (patch) | |
| tree | ff3c74bd2c255a4bacaf91e665f24611086d49fa /src/patch_parse.c | |
| parent | 5d773a1833ef6d0fb2093e00b1cf9bfb668a1ffc (diff) | |
| parent | de543e297d85f1ac700c2e5a83e70b1bd32b9518 (diff) | |
| download | libgit2-a3d8a43755dae7292857a0afa847601d2a85a1af.tar.gz | |
Merge pull request #5298 from pks-t/pks/patch-whitespace-only-paths
patch_parse: fix segfault when header path contains whitespace only
Diffstat (limited to 'src/patch_parse.c')
| -rw-r--r-- | src/patch_parse.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c index 5032e35c8..1bf0190c3 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -69,27 +69,24 @@ static int parse_header_path_buf(git_buf *path, git_patch_parse_ctx *ctx, size_t { int error; - if (!path_len) - return git_parse_err("patch contains empty path at line %"PRIuZ, - ctx->parse_ctx.line_num); - if ((error = git_buf_put(path, ctx->parse_ctx.line, path_len)) < 0) - goto done; + return error; git_parse_advance_chars(&ctx->parse_ctx, path_len); git_buf_rtrim(path); - if (path->size > 0 && path->ptr[0] == '"') - error = git_buf_unquote(path); - - if (error < 0) - goto done; + if (path->size > 0 && path->ptr[0] == '"' && + (error = git_buf_unquote(path)) < 0) + return error; git_path_squash_slashes(path); -done: - return error; + if (!path->size) + return git_parse_err("patch contains empty path at line %"PRIuZ, + ctx->parse_ctx.line_num); + + return 0; } static int parse_header_path(char **out, git_patch_parse_ctx *ctx) |
