dotnet/runtime

ILAsm: Fail on string literals containing "... /* ..." within disabled #ifdef block

Open

#12.418 aperta il 4 apr 2019

Vedi su GitHub
 (9 commenti) (0 reazioni) (0 assegnatari)C# (5445 fork)batch import
Priority:3area-ILTools-coreclrbughelp wanted

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

ILAsm.exe incorrectly opens a C-style block comment /* ... */ when the opening sequence /* appears in a string literal that occurs within the disabled portion(s) of an #ifdef ... #else ... #endif preprocessor block.

The two code examples shown below are identical except the latter contains an #ifdef block illustrating the problem. The first example works correctly, but the second causes ILAsm.exe to fail.

In the second example, since the symbol __NOT_DEFINED__ is not defined, the first part of the #ifdef block should be ignored. The excluded part of the #ifdef block contains a string literal which happens to contain the block comment opening sequence /*.

app_ok.il :

.assembly extern mscorlib { .ver 4:0:0:0 auto }
.assembly app_ok { }
.module app_ok.exe
.class Program
{
    .method static void Main()
    {
        .entrypoint
        
        ldstr "foo /* bar"
        call void [mscorlib]System.Console::WriteLine(string)
        ret
    }
}

result - ok :

D:\>ilasm /nologo /quiet app_ok.il
D:\>app_ok.exe
foo /* bar
D:\>

app_fail.il :

.assembly extern mscorlib { .ver 4:0:0:0 auto }
.assembly app_fail { }
.module app_fail.exe
.class Program
{
    .method static void Main()
    {
        .entrypoint

#ifdef __NOT_DEFINED__
        ldstr "foo /* bar"
#else
        ldstr "etc. (doesn't matter)"
#endif
        call void [mscorlib]System.Console::WriteLine(string)
        ret
    }
}

result - failure :

D:\>ilasm /nologo /quiet app_fail.il
app_fail.il(23) : error : syntax error at token '' in:

***** FAILURE *****
D:\>

Error:ILAsm.exe incorrectly considers the text "/*", which appears within the string literal, to be an active block comment opening sequence.

This only occurs within disabled preprocessor blocks. If the /* portion of the text is removed from the failure example, or if the (incorrectly-opened) block comment is "properly" closed via a */ sequence within the disabled section (this can be either within the string literal or subsequently), then the error goes away and the ILAsm.exe command succeeds.

Expected:The happenstance contents of a string literal should not affect the success or failure of an ILAsm.exe invocation.

Notes:Within preprocessor blocks that are enabled (active), string literals containing the comment sequence are handled correctly (not interpreted).

The same failure also occurs when the /* sequence appears outside of a string literal within a disabled preprocessor block, but this condition seems less obviously erroneous.

Guida contributor