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

DWORD * is replaced with enum (not pointer) #337

Closed
krzysdz opened this issue Mar 12, 2021 · 2 comments · Fixed by #344
Closed

DWORD * is replaced with enum (not pointer) #337

krzysdz opened this issue Mar 12, 2021 · 2 comments · Fixed by #344
Assignees
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working

Comments

@krzysdz
Copy link

krzysdz commented Mar 12, 2021

In the 10.0.19041.5-preview.39 NuGet the DWORD * CryptQueryObject parameters (pdwContentType and pdwFormatType) have CERT_QUERY_FLAGS and CERT_QUERY_FORMAT_TYPE types respectively.

The same issue applies to CryptAcquireCertificatePrivateKey (pdwKeySpec). I didn't find any more cases - most DWORD * parameters I found in the Windows SDK header files are just uint * in the .winmd.

The original declaration:

WINCRYPT32API
BOOL
WINAPI
CryptQueryObject(
    _In_ DWORD                    dwObjectType,
    _In_ const void               *pvObject,
    _In_ DWORD                    dwExpectedContentTypeFlags,
    _In_ DWORD                    dwExpectedFormatTypeFlags,
    _In_ DWORD                    dwFlags,
    _Out_opt_ DWORD               *pdwMsgAndCertEncodingType,
    _Out_opt_ DWORD               *pdwContentType,
    _Out_opt_ DWORD               *pdwFormatType,
    _Out_opt_ HCERTSTORE          *phCertStore,
    _Out_opt_ HCRYPTMSG           *phMsg,
    _Outptr_opt_result_maybenull_ const void **ppvContext
    );

Declaration in the .winmd (formatted):

[DllImport("CRYPT32", ExactSpelling = true, SetLastError = true)]
public unsafe static extern BOOL CryptQueryObject(
	[In] CryptQueryObject_dwObjectTypeFlags dwObjectType, // This enum does not contain flags (and has no
	                                                      // [Flags] attribute), but has "Flags" in name
	[In][Const] void* pvObject,
	[In] CERT_QUERY_FLAGS dwExpectedContentTypeFlags, // Contains invalid "flags", it should contain only
	                                                  // the CERT_QUERY_CONTENT_FLAG_* ones
	[In] CERT_QUERY_FORMAT_FLAGS dwExpectedFormatTypeFlags,
	[In] uint dwFlags,
	[Optional][Out] CertOpenStore_dwEncodingType pdwMsgAndCertEncodingType,
	[Optional][Out] CERT_QUERY_FLAGS pdwContentType,      // It should be a pointer, not a value. The enum
	                                                      // contains too many values and should not be marked
							      // with the [Flags] attribute. This enum should
							      // contain only /CERT_QUERY_CONTENT_(?!FLAG_)\w+/
							      // values.
	[Optional][Out] CERT_QUERY_FORMAT_TYPE pdwFormatType, // It should be a pointer, not a value
	[Optional][Out] void** phCertStore,
	[Optional][Out] void** phMsg,
	[Optional][Out][Const] void** ppvContext);
@krzysdz
Copy link
Author

krzysdz commented Mar 12, 2021

This problem can also affect other pointer type parameters such as LPDWORD.
The InternetGetConnectedStateExA/W functions have _Out_opt_ LPDWORD lpdwFlags as the first parameter, but in the metadata the pointer is lost:

InternetGetConnectedStateExW declaration in the .winmd file

@mikebattista mikebattista added the broken api An API is inaccurate and could lead to runtime failure label Mar 12, 2021
@mikebattista
Copy link
Collaborator

Thanks for filing. We recently added some automation to improve our enum coverage, and this looks like a bug with that not preserving pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broken api An API is inaccurate and could lead to runtime failure bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants