summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-07-20 18:49:48 +0200
committerPatrick Steinhardt <ps@pks.im>2020-03-26 16:20:11 +0100
commitc159cceb382494e9544faf3ed8a04aa3212dcd5a (patch)
tree6d13ddaa34fe59235c6ffeec25d5777d2c73437a
parent16dbedc97231c2ee11e0a66e9d56ecba19937249 (diff)
downloadlibgit2-c159cceb382494e9544faf3ed8a04aa3212dcd5a.tar.gz
patch_parse: fix segfault due to line containing static contents
With commit dedf70ad2 (patch_parse: do not depend on parsed buffer's lifetime, 2019-07-05), all lines of the patch are allocated with `strdup` to make lifetime of the parsed patch independent of the buffer that is currently being parsed. In patch b08932824 (patch_parse: ensure valid patch output with EOFNL, 2019-07-11), we introduced another code location where we add lines to the parsed patch. But as that one was implemented via a separate pull request, it wasn't converted to use `strdup`, as well. As a consequence, we generate a segfault when trying to deallocate the potentially static buffer that's now in some of the lines. Use `git__strdup` to fix the issue.
-rw-r--r--src/patch_parse.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 8b464d05e..b649a1c09 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -653,7 +653,7 @@ static int parse_hunk_body(
memset(line, 0x0, sizeof(git_diff_line));
- line->content = ctx->parse_ctx.line;
+ line->content = git__strdup(ctx->parse_ctx.line);
line->content_len = ctx->parse_ctx.line_len;
line->content_offset = ctx->parse_ctx.content_len - ctx->parse_ctx.remain_len;
line->origin = eof_for_origin(last_origin);