-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BinSkim .NET Updates to version 9 #1024
base: main
Are you sure you want to change the base?
Changes from all commits
015326b
000e522
58f74d1
9c5a907
3653775
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ x64/ | |
|
||
# Workaround for an msbuild/dotnet bug on Linux | ||
src/BinSkimLinux.sln | ||
.vscode/settings.json |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,13 +121,18 @@ | |
/// <summary> | ||
/// Reads the string from the current position in the stream. | ||
/// </summary> | ||
[HandleProcessCorruptedStateExceptions] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be reading the docs wrong, but with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well I went over the docs, and as of now the only option seems to be try catch, so I did it with the generic try catch clause. But I'm more than open to the suggestions for improvements :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm kind of wondering if
It doesn't seem like we have any automated tests for this right? |
||
public string ReadString() | ||
{ | ||
string result = Marshal.PtrToStringAnsi(pointer + Position); | ||
|
||
Position += result.Length + 1; | ||
return result; | ||
try | ||
{ | ||
string result = Marshal.PtrToStringAnsi(pointer + Position); | ||
Position += result.Length + 1; | ||
return result; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new InvalidOperationException("Failed to read string from memory.", ex); | ||
} | ||
Comment on lines
+132
to
+135
Check notice Code scanning / CodeQL Generic catch clause Note
Generic catch clause.
|
||
} | ||
|
||
/// <summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase | ||
{ | ||
public static class ResourceReleaser | ||
{ | ||
public static void Release(object resource) | ||
{ | ||
if (resource != null && Marshal.IsComObject(resource) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
Marshal.ReleaseComObject(resource); | ||
} | ||
else if (resource is IDisposable disposable) | ||
{ | ||
disposable.Dispose(); | ||
} | ||
} | ||
|
||
public static object GetObjectForIUnknown(nint pointer) | ||
{ | ||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) | ||
? Marshal.GetObjectForIUnknown(pointer) | ||
: new object(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: is this intentional?