summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-03-10 16:42:55 +0100
committerPatrick Steinhardt <ps@pks.im>2016-03-11 14:20:15 +0100
commite850e98ddbcca9d51f412482e3bf16b2d5c36bc8 (patch)
treeb9ee32b09c53aee8a467da71ddc5f52a3c88bec2
parent8a4a343a2b230acc69ba13131355f8299b4483d3 (diff)
downloadlibgit2-e850e98ddbcca9d51f412482e3bf16b2d5c36bc8.tar.gz
blame: handle error when resoling HEAD in normalize_options
When normalizing options we try to look up HEAD's OID. While this action may fail in malformed repositories we never check the return value of the function. Fix the issue by converting `normalize_options` to actually return an error and handle the error in `git_blame_file`.
-rw-r--r--src/blame.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/blame.c b/src/blame.c
index 2daf91591..2c8584ba5 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -178,7 +178,7 @@ const git_blame_hunk *git_blame_get_hunk_byline(git_blame *blame, size_t lineno)
return NULL;
}
-static void normalize_options(
+static int normalize_options(
git_blame_options *out,
const git_blame_options *in,
git_repository *repo)
@@ -190,7 +190,9 @@ static void normalize_options(
/* No newest_commit => HEAD */
if (git_oid_iszero(&out->newest_commit)) {
- git_reference_name_to_id(&out->newest_commit, repo, "HEAD");
+ if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) {
+ return -1;
+ }
}
/* min_line 0 really means 1 */
@@ -204,6 +206,8 @@ static void normalize_options(
out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES)
out->flags |= GIT_BLAME_TRACK_COPIES_SAME_FILE;
+
+ return 0;
}
static git_blame_hunk *split_hunk_in_vector(
@@ -362,7 +366,8 @@ int git_blame_file(
git_blame *blame = NULL;
assert(out && repo && path);
- normalize_options(&normOptions, options, repo);
+ if ((error = normalize_options(&normOptions, options, repo)) < 0)
+ goto on_error;
blame = git_blame__alloc(repo, normOptions, path);
GITERR_CHECK_ALLOC(blame);