Jan 21

.NET Bestfit Unicode Conversion for P/Invoke

Category: Security

sherlock holmes ritchie When performing a standard p/invoke method call in which a .NET string must be converted to an unmanaged LPSTR (char*), the .NET runtime performs a "bestfit" conversion.  This means some Unicode characters will be converted down to ASCII characters based on some mapping information.  This "bestfit" conversion can allow an attacker to bypass input validation filters.  For example, a filename might be checked to make sure it does not contain a backslash ("\") character, or two periods ("..").  By using Unicode characters an attacker could by pass those checks by providing a Unicode character that will be converted to the required ASCII character during the marshaling of the string.

Full article with character map.

3 comments

3 Comments so far

  1. Andrew Baughman February 27th, 2008 4:36 pm

    I was wondering if you graduated from Lakota HS in West Chester, 1988. I had a friend named Michael Eddington, are you him?

  2. Clint March 5th, 2008 7:08 am

    FxCop has a security rule for this situation:
    http://msdn2.microsoft.com/en-us/library/ms182319.aspx

  3. Michael Eddington May 23rd, 2008 9:56 am

    Andrew: nope, thats not me.

Leave a comment