diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-02-27 16:08:52 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-03-06 10:39:58 +0100 |
commit | 7372cfd6c2acee87334ff49609d67dfc485583c8 (patch) | |
tree | 7b7cb96190af70e5707bf7ecc4f1ddc9fe968fd9 /src/buildtool/file_system/git_repo.cpp | |
parent | 0f857046ddd459695f8dd890ca580cdd803d1810 (diff) | |
download | justbuild-7372cfd6c2acee87334ff49609d67dfc485583c8.tar.gz |
GitRepo: Add missing retval check for git oid libgit2 calls
Diffstat (limited to 'src/buildtool/file_system/git_repo.cpp')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 0b56099c..994f0654 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -654,13 +654,21 @@ auto GitRepo::GetSubtreeFromCommit(std::string const& commit, // preferably with a "fake" repository! if (not IsRepoFake()) { (*logger)( - "WARNING: subtree id retireval from commit called on a real " + "WARNING: subtree id retrieval from commit called on a real " "repository!\n", false /*fatal*/); } // get commit object git_oid commit_oid; - git_oid_fromstr(&commit_oid, commit.c_str()); + if (git_oid_fromstr(&commit_oid, commit.c_str()) != 0) { + (*logger)( + fmt::format("commit ID parsing in git repository {} failed " + "with:\n{}", + GetGitCAS()->git_path_.string(), + GitLastError()), + true /*fatal*/); + return std::nullopt; + } git_commit* commit_ptr{nullptr}; if (git_commit_lookup(&commit_ptr, repo_.get(), &commit_oid) != 0) { @@ -749,7 +757,15 @@ auto GitRepo::GetSubtreeFromTree(std::string const& tree_id, } // get tree object from tree id git_oid tree_oid; - git_oid_fromstr(&tree_oid, tree_id.c_str()); + if (git_oid_fromstr(&tree_oid, tree_id.c_str()) != 0) { + (*logger)( + fmt::format("tree ID parsing in git repository {} failed " + "with:\n{}", + GetGitCAS()->git_path_.string(), + GitLastError()), + true /*fatal*/); + return std::nullopt; + } git_tree* tree_ptr{nullptr}; if (git_tree_lookup(&tree_ptr, repo_.get(), &tree_oid) != 0) { @@ -864,7 +880,16 @@ auto GitRepo::CheckCommitExists(std::string const& commit, } // lookup commit in current repo state git_oid commit_oid; - git_oid_fromstr(&commit_oid, commit.c_str()); + if (git_oid_fromstr(&commit_oid, commit.c_str()) != 0) { + (*logger)( + fmt::format("commit ID parsing in git repository {} failed " + "with:\n{}", + GetGitCAS()->git_path_.string(), + GitLastError()), + true /*fatal*/); + return std::nullopt; + } + git_commit* commit_obj = nullptr; auto lookup_res = git_commit_lookup(&commit_obj, repo_.get(), &commit_oid); |