Skip to content

Conversation

@powercode
Copy link
Collaborator

@powercode powercode commented Aug 21, 2018

PR Summary

#7572

The current code mixes Ansi version of GetStartupInfoA with Unicode marshalling. This leads to a heap corruption that manifests in a crash a few lines down.

This commit simplifies the interop struct, using IntPtr instead of string since we have no usage for the strings. With that change, all fields are blitable, making the marshaller both simpler and faster.

GetStartupInfoA is documented to throw and exception, not set last error, So I changed to SetLastError = false.

GetStartupInfoW does not fail, indicated by the void return type.
I also made the reserved fields private, and all fields readonly.

PR Checklist

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor comment.

internal static extern void GetStartupInfo(out StartUpInfo lpStartupInfo);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
[StructLayout(LayoutKind.Sequential)]
Copy link
Collaborator

@iSazonov iSazonov Aug 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment why we use IntPtr for strings - this help us avoid problems in future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@adityapatwardhan adityapatwardhan merged commit 50626a1 into PowerShell:master Aug 24, 2018
@TravisEz13 TravisEz13 added this to the v6.1.0 milestone Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants