Exit gracefully when running ildasm -nat against unsupported ni file. (dotnet/coreclr...
authorJim Ma <mazong1123@gmail.com>
Sat, 8 Apr 2017 16:43:47 +0000 (00:43 +0800)
committerJan Kotas <jkotas@microsoft.com>
Sat, 8 Apr 2017 16:43:47 +0000 (09:43 -0700)
ildasm -nat only works for fragile native images (ie CoreLib only by default).
Running ildasm -nat against unsupported native images would cause a segmentation fault. This PR checks pNativeHeader->Signature == CORCOMPILE_SIGNATURE and end the program with a meaningful error message.

fix dotnet/coreclr#10247

Commit migrated from https://github.com/dotnet/coreclr/commit/20248521af31e2307fcd728f1ebbf7877bb5ee59

src/coreclr/src/ildasm/dasm.cpp

index 68cfa2a..3d172f0 100644 (file)
@@ -7370,6 +7370,13 @@ BOOL DumpFile()
         }
         CORCOMPILE_HEADER * pNativeHeader;
         g_pPELoader->getVAforRVA(VAL32(g_CORHeader->ManagedNativeHeader.VirtualAddress), (void**)&pNativeHeader);
+
+        if (pNativeHeader->Signature != CORCOMPILE_SIGNATURE)
+        {
+            printError( g_pFile, "/native only works on NGen images." );
+            goto exit;
+        }
+
         g_pPELoader->getVAforRVA(VAL32(pNativeHeader->ManifestMetaData.VirtualAddress), &g_pMetaData);
         g_cbMetaData = VAL32(pNativeHeader->ManifestMetaData.Size);
     }