From 129d70313c3959005f6676ad9eb573468e448648 Mon Sep 17 00:00:00 2001 From: J Wyman Date: Mon, 8 Jun 2015 14:50:47 -0700 Subject: [PATCH 1/2] Fixes NRE issues found by Covertity in Repository.cs --- LibGit2Sharp/Repository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index 79c9077bc..fef0ccac1 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -476,7 +476,7 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know using (GitObjectSafeHandle obj = Proxy.git_object_lookup(handle, id, type)) { - if (obj == null) + if (obj == null || obj.IsInvalid) { return null; } From fba0a7352d795cc81f995fb1db10778d9bfe8ba5 Mon Sep 17 00:00:00 2001 From: J Wyman Date: Mon, 8 Jun 2015 14:51:52 -0700 Subject: [PATCH 2/2] Fixes NRE issues found by Covertity in ObjectDatabase.cs --- LibGit2Sharp/ObjectDatabase.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index a79965613..05d2f5f6b 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -365,7 +365,9 @@ public virtual Commit CreateCommit(Signature author, Signature committer, string ObjectId commitId = Proxy.git_commit_create(repo.Handle, null, author, committer, message, tree, parentIds); - return repo.Lookup(commitId); + Commit commit = repo.Lookup(commitId); + Ensure.GitObjectIsNotNull(commit, commitId.Sha); + return commit; } /// @@ -454,6 +456,8 @@ public virtual string ShortenObjectId(GitObject gitObject) /// A short string representation of the . public virtual string ShortenObjectId(GitObject gitObject, int minLength) { + Ensure.ArgumentNotNull(gitObject, "gitObject"); + if (minLength <= 0 || minLength > ObjectId.HexSize) { throw new ArgumentOutOfRangeException("minLength", minLength, @@ -462,6 +466,11 @@ public virtual string ShortenObjectId(GitObject gitObject, int minLength) string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id); + if (shortSha == null) + { + throw new LibGit2SharpException("Unable to abbreviate SHA-1 value for GitObject " + gitObject.Id); + } + if (minLength <= shortSha.Length) { return shortSha;