Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f17ed63

Browse files
pks-tEdward Thomson
authored and
Edward Thomson
committed
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`.
1 parent dd78d7d commit f17ed63

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/blame.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const git_blame_hunk *git_blame_get_hunk_byline(git_blame *blame, size_t lineno)
178178
return NULL;
179179
}
180180

181-
static void normalize_options(
181+
static int normalize_options(
182182
git_blame_options *out,
183183
const git_blame_options *in,
184184
git_repository *repo)
@@ -190,7 +190,9 @@ static void normalize_options(
190190

191191
/* No newest_commit => HEAD */
192192
if (git_oid_iszero(&out->newest_commit)) {
193-
git_reference_name_to_id(&out->newest_commit, repo, "HEAD");
193+
if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) {
194+
return -1;
195+
}
194196
}
195197

196198
/* min_line 0 really means 1 */
@@ -204,6 +206,8 @@ static void normalize_options(
204206
out->flags |= GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES;
205207
if (out->flags & GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES)
206208
out->flags |= GIT_BLAME_TRACK_COPIES_SAME_FILE;
209+
210+
return 0;
207211
}
208212

209213
static git_blame_hunk *split_hunk_in_vector(
@@ -362,7 +366,8 @@ int git_blame_file(
362366
git_blame *blame = NULL;
363367

364368
assert(out && repo && path);
365-
normalize_options(&normOptions, options, repo);
369+
if ((error = normalize_options(&normOptions, options, repo)) < 0)
370+
goto on_error;
366371

367372
blame = git_blame__alloc(repo, normOptions, path);
368373
GITERR_CHECK_ALLOC(blame);

0 commit comments

Comments
 (0)