Skip to content

The friendly overload for RtlInitUnicodeString() looks incredibly dangerous. #1662

@mjr4077au

Description

@mjr4077au

Actual behavior

Below is the generated source. I believe this buffer will be left with a dangling pointer to the SourceStringLocal pointer within this wrapper.

/// <inheritdoc cref="RtlInitUnicodeString(winmdroot.Foundation.UNICODE_STRING*, winmdroot.Foundation.PCWSTR)"/>
[OverloadResolutionPriority(1)]
internal static unsafe void RtlInitUnicodeString(ref winmdroot.Foundation.UNICODE_STRING DestinationString, string SourceString)
{
	fixed (char* SourceStringLocal = SourceString)
	{
		fixed (winmdroot.Foundation.UNICODE_STRING* DestinationStringLocal = &DestinationString)
		{
			PInvoke.RtlInitUnicodeString(DestinationStringLocal, SourceStringLocal);
		}
	}
}

Expected behavior

That this friendly overload simply not exist.

Repro steps

  1. NativeMethods.txt content:
RtlInitUnicodeString
  1. NativeMethods.json content (if present): N/A

  2. Any of your own code that should be shared? N/A

Context

  • CsWin32 version: 0.3.269
  • Win32Metadata version: N/A
  • Target Framework: net472
  • LangVersion: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions