[NTOS:KD] Check for valid LoaderBlock and LoaderBlock->LoadOptions pointers when...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 2 Nov 2019 00:07:29 +0000 (01:07 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 3 Nov 2019 04:08:33 +0000 (05:08 +0100)
ntoskrnl/kd/kdinit.c

index 3a7071d..f5e1c48 100644 (file)
@@ -84,7 +84,6 @@ KdpGetDebugMode(PCHAR Currentp2)
             }
         }
     }
             }
         }
     }
-
     /* Check for Debug Log Debugging */
     else if (!_strnicmp(p2, "FILE", 4))
     {
     /* Check for Debug Log Debugging */
     else if (!_strnicmp(p2, "FILE", 4))
     {
@@ -100,7 +99,6 @@ KdpGetDebugMode(PCHAR Currentp2)
             KdpLogFileName.Buffer = p1;
         }
     }
             KdpLogFileName.Buffer = p1;
         }
     }
-
     /* Check for BOCHS Debugging */
     else if (!_strnicmp(p2, "BOCHS", 5))
     {
     /* Check for BOCHS Debugging */
     else if (!_strnicmp(p2, "BOCHS", 5))
     {
@@ -108,7 +106,6 @@ KdpGetDebugMode(PCHAR Currentp2)
         p2 += 5;
         KdpDebugMode.Bochs = TRUE;
     }
         p2 += 5;
         KdpDebugMode.Bochs = TRUE;
     }
-
     /* Check for GDB Debugging */
     else if (!_strnicmp(p2, "GDB", 3))
     {
     /* Check for GDB Debugging */
     else if (!_strnicmp(p2, "GDB", 3))
     {
@@ -122,7 +119,6 @@ KdpGetDebugMode(PCHAR Currentp2)
         SharedUserData->KdDebuggerEnabled = TRUE;
         WrapperInitRoutine = KdpGdbStubInit;
     }
         SharedUserData->KdDebuggerEnabled = TRUE;
         WrapperInitRoutine = KdpGdbStubInit;
     }
-
     /* Check for PICE Debugging */
     else if (!_strnicmp(p2, "PICE", 4))
     {
     /* Check for PICE Debugging */
     else if (!_strnicmp(p2, "PICE", 4))
     {
@@ -175,39 +171,55 @@ KdInitSystem(ULONG BootPhase,
 {
     ULONG Value;
     ULONG i;
 {
     ULONG Value;
     ULONG i;
-    PCHAR CommandLine, Port, BaudRate, Irq;
+    PCHAR CommandLine, Port = NULL, BaudRate = NULL, Irq = NULL;
 
     /* Set Default Port Options */
     if (BootPhase == 0)
     {
 
     /* Set Default Port Options */
     if (BootPhase == 0)
     {
-        /* Get the Command Line */
-        CommandLine = LoaderBlock->LoadOptions;
-
-        /* Upcase it */
-        _strupr(CommandLine);
-
-        /* XXX Check for settings that we support */
-        if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE;
-        else if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE;
-        else if (strstr(CommandLine, "DEBUG"))
+        /* Check if we have a loader block */
+        if (LoaderBlock)
         {
         {
-            /* Enable the kernel debugger */
-            KdDebuggerNotPresent = FALSE;
-            KdDebuggerEnabled = TRUE;
+            /* Check if we have a command line */
+            CommandLine = LoaderBlock->LoadOptions;
+            if (CommandLine)
+            {
+                /* Upcase it */
+                _strupr(CommandLine);
+
+                /* XXX Check for settings that we support */
+                if (strstr(CommandLine, "NODEBUG")) KdDebuggerEnabled = FALSE;
+                else if (strstr(CommandLine, "CRASHDEBUG")) KdDebuggerEnabled = FALSE;
+                else if (strstr(CommandLine, "DEBUG"))
+                {
+                    /* Enable the kernel debugger */
+                    KdDebuggerNotPresent = FALSE;
+                    KdDebuggerEnabled = TRUE;
 #ifdef KDBG
 #ifdef KDBG
-            /* Get the KDBG Settings */
-            KdbpGetCommandLineSettings(LoaderBlock->LoadOptions);
+                    /* Get the KDBG Settings */
+                    KdbpGetCommandLineSettings(LoaderBlock->LoadOptions);
 #endif
 #endif
+                }
+
+                /* Get the port and baud rate */
+                Port = strstr(CommandLine, "DEBUGPORT");
+                BaudRate = strstr(CommandLine, "BAUDRATE");
+                Irq = strstr(CommandLine, "IRQ");
+            }
+            else
+            {
+                /* No command line options? Disable debugger by default */
+                KdDebuggerEnabled = FALSE;
+            }
+        }
+        else
+        {
+            /* Called from a bugcheck or a re-enable. Unconditionally enable KD */
+            KdDebuggerEnabled = TRUE;
         }
 
         /* Let user-mode know our state */
         SharedUserData->KdDebuggerEnabled = KdDebuggerEnabled;
 
         }
 
         /* Let user-mode know our state */
         SharedUserData->KdDebuggerEnabled = KdDebuggerEnabled;
 
-        /* Get the port and baud rate */
-        Port = strstr(CommandLine, "DEBUGPORT");
-        BaudRate = strstr(CommandLine, "BAUDRATE");
-        Irq = strstr(CommandLine, "IRQ");
-
         /* Check if we got the /DEBUGPORT parameter(s) */
         while (Port)
         {
         /* Check if we got the /DEBUGPORT parameter(s) */
         while (Port)
         {