Skip to content
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

WINHTTP_CONNECTION_INFO maybe incorrect padding #368

Closed
GF-Huang opened this issue Jan 20, 2023 · 1 comment
Closed

WINHTTP_CONNECTION_INFO maybe incorrect padding #368

GF-Huang opened this issue Jan 20, 2023 · 1 comment

Comments

@GF-Huang
Copy link
Contributor

Describe the bug and how to reproduce

The WINHTTP_CONNECTION_INFO maybe has wrong padding between field cbSize and LocalAddress.

C#

image

C++

image

What code is involved

uint bufferLength = (uint)Marshal.SizeOf<WINHTTP_CONNECTION_INFO>();
using var buffer = new SafeByteArray((int)bufferLength);

if (WinHttpQueryOption(hInternet, WINHTTP_OPTION.WINHTTP_OPTION_CONNECTION_INFO, buffer, ref bufferLength)) {
    var info1 = Marshal.PtrToStructure<WINHTTP_CONNECTION_INFO>(buffer);
    Console.WriteLine($"{SockaddrStorageToEndPoint(info1.LocalAddress)} -> {SockaddrStorageToEndPoint(info1.RemoteAddress)}");

} else {
    Console.WriteLine(GetLastError());   // Always go here, because the WINHTTP_CONNECTION_INFO size incorrect.
}

Expected behavior

Marshal.SizeOf<WINHTTP_CONNECTION_INFO>() should be 264.

@GF-Huang
Copy link
Contributor Author

GF-Huang commented Jan 20, 2023

I try to define a duplicate of WINHTTP_CONNECTION_INFO with Pack = 8, which fix this issue.

[StructLayout(LayoutKind.Sequential, Pack = 4)]

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

No branches or pull requests

2 participants