8000 Merge pull request #1081 from whoisj/fix-coverity-nre-issues · leoniDEV/libgit2sharp@738c263 · GitHub
[go: up one dir, main page]

Skip to content

Commit 738c263

Browse files
committed
Merge pull request libgit2#1081 from whoisj/fix-coverity-nre-issues
Fixes Coverity NullReferenceException Issues
2 parents 7cb2d7e + fba0a73 commit 738c263

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

LibGit2Sharp/ObjectDatabase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ public virtual Commit CreateCommit(Signature author, Signature committer, string
365365

366366
ObjectId commitId = Proxy.git_commit_create(repo.Handle, null, author, committer, message, tree, parentIds);
367367

368-
return repo.Lookup<Commit>(commitId);
368+
Commit commit = repo.Lookup<Commit>(commitId);
369+
Ensure.GitObjectIsNotNull(commit, commitId.Sha);
370+
return commit;
369371
}
370372

371373
/// <summary>
@@ -454,6 +456,8 @@ public virtual string ShortenObjectId(GitObject gitObject)
454456
/// <returns>A short string representation of the <see cref="ObjectId"/>.</returns>
455457
public virtual string ShortenObjectId(GitObject gitObject, int minLength)
456458
{
459+
Ensure.ArgumentNotNull(gitObject, "gitObject");
460+
457461
if (minLength <= 0 || minLength > ObjectId.HexSize)
458462
{
459463
throw new ArgumentOutOfRangeException("minLength", minLength,
@@ -462,6 +466,11 @@ public virtual string ShortenObjectId(GitObject gitObject, int minLength)
462466

463467
string shortSha = Proxy.git_object_short_id(repo.Handle, gitObject.Id);
464468

469+
if (shortSha == null)
470+
{
471+
throw new LibGit2SharpException("Unable to abbreviate SHA-1 value for GitObject " + gitObject.Id);
472+
}
473+
465474
if (minLength <= shortSha.Length)
466475
{
467476
return shortSha;

LibGit2Sharp/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath know
476476

477477
using (GitObjectSafeHandle obj = Proxy.git_object_lookup(handle, id, type))
478478
{
479-
if (obj == null)
479+
if (obj == null || obj.IsInvalid)
480480
{
481481
return null;
482482
}

0 commit comments

Comments
 (0)
0