- DBGKD_WAIT_STATE_CHANGE64 is used in KD protocol 5, not number 6 that we use. Proto...
[reactos.git] / reactos / lib / rossym / frommem.c
index e7858ac..f03274e 100644 (file)
@@ -3,7 +3,7 @@
  * PROJECT:         ReactOS kernel
  * FILE:            lib/rossym/frommem.c
  * PURPOSE:         Creating rossym info from an in-memory image
- * 
+ *
  * PROGRAMMERS:     Ge van Geldorp (gvg@reactos.com)
  */
 
@@ -11,9 +11,7 @@
 #include <ntddk.h>
 #include <reactos/rossym.h>
 #include "rossympriv.h"
-#ifdef _MSC_VER
-#include "ntimage.h"
-#endif
+#include <ntimage.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -24,8 +22,9 @@ RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymI
   PIMAGE_DOS_HEADER DosHeader;
   PIMAGE_NT_HEADERS NtHeaders;
   PIMAGE_SECTION_HEADER SectionHeader;
-  unsigned SectionIndex;
-  char SectionName[IMAGE_SIZEOF_SHORT_NAME];
+  ULONG SectionIndex;
+  BOOLEAN RosSymSectionFound = FALSE;
+  CHAR SectionName[IMAGE_SIZEOF_SHORT_NAME];
 
   /* Check if MZ header is valid */
   DosHeader = (PIMAGE_DOS_HEADER) ImageStart;
@@ -58,11 +57,13 @@ RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymI
     {
       if (0 == memcmp(SectionName, SectionHeader->Name, IMAGE_SIZEOF_SHORT_NAME))
         {
+          RosSymSectionFound = TRUE;
           break;
         }
       SectionHeader++;
     }
-  if (NtHeaders->FileHeader.NumberOfSections <= SectionIndex)
+
+  if (!RosSymSectionFound)
     {
       DPRINT("No %s section found\n", ROSSYM_SECTION_NAME);
       return FALSE;
@@ -72,10 +73,16 @@ RosSymCreateFromMem(PVOID ImageStart, ULONG_PTR ImageSize, PROSSYM_INFO *RosSymI
   if (ImageSize < SectionHeader->PointerToRawData + SectionHeader->SizeOfRawData
       || SectionHeader->SizeOfRawData < sizeof(ROSSYM_HEADER))
     {
-      DPRINT1("Invalid %s section\n", ROSSYM_SECTION_NAME);
+      DPRINT("Invalid %s section\n", ROSSYM_SECTION_NAME);
       return FALSE;
     }
 
+  if (SectionHeader->VirtualAddress + SectionHeader->Misc.VirtualSize > ImageSize)
+  {
+      DPRINT("Bad %s section virtual size!\n", ROSSYM_SECTION_NAME);
+      return FALSE;
+  }
+
   /* Load it */
   return RosSymCreateFromRaw((char *) ImageStart + SectionHeader->VirtualAddress,
                              SectionHeader->SizeOfRawData, RosSymInfo);