Skip to content

ITypeInfo methods taking SysFreeStringSafeHandle are unsafe #1442

@colejohnson66

Description

@colejohnson66

Actual behavior

For ITypeInfo COM object:

internal static unsafe void GetNames(this winmdroot.System.Com.ITypeInfo @this, int memid, out SysFreeStringSafeHandle rgBstrNames, uint cMaxNames, out uint pcNames)
{
    winmdroot.Foundation.BSTR rgBstrNamesLocal;
    @this.GetNames(memid, &rgBstrNamesLocal, cMaxNames, out pcNames);
    rgBstrNames = new SysFreeStringSafeHandle(rgBstrNamesLocal, ownsHandle: true);
}

Expected behavior

Either an array is provided on the out parameter, or the cMaxNames parameter is replaced with a constant 1.

Repro steps

  1. NativeMethods.txt content:
ITypeInfo
  1. NativeMethods.json content (if present):
  1. Any of your own code that should be shared?
// cause a buffer overrun
info.GetNames(func.memid, out SysFreeStringSafeHandle name, 2, out uint names);

Context

  • CsWin32 version: 0.3.183
  • Target Framework: net9.0

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