8000 Fixes potential NRE conditions · odedw/libgit2sharp@d1e43bd · GitHub
[go: up one dir, main page]

Skip to content

Commit d1e43bd

Browse files
author
J Wyman
committed
Fixes potential NRE conditions
1 parent 0a72962 commit d1e43bd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

LibGit2Sharp/Core/EncodingMarshaler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual Object MarshalNativeToManaged(IntPtr pNativeData)
5959

6060
public static unsafe IntPtr FromManaged(Encoding encoding, String value)
6161
{
62-
if (value == null)
62+
if (encoding == null || value == null)
6363
{
6464
return IntPtr.Zero;
6565
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitE
133133
private static void HandleError(int result)
134134
{
135135
string errorMessage;
136-
GitError error = NativeMethods.giterr_last().MarshalAsGitError();
136+
GitError error = null;
137+
var errHandle = NativeMethods.giterr_last();
138+
139+
if (errHandle != null && !errHandle.IsInvalid)
140+
{
141+
error = errHandle.MarshalAsGitError();
142+
}
137143

138144
if (error == null)
139145
{

0 commit comments

Comments
 (0)
0