[FREELDR] Some initialization fixes.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 4 Aug 2019 15:35:46 +0000 (17:35 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 4 Aug 2019 15:47:04 +0000 (17:47 +0200)
- Initialize BootPath and BootOptions buffers when fallback behaviour is not taken.
- Correctly skip all the understood whitespace (space & tabs) and the
  quotes before reading the boot options when using the alternative syntax:

  [Operating Systems]
  section_name = "ReactOS" /bootoptions

  Fixes the minor regression introduced in 370e8564 (r43875).

boot/freeldr/freeldr/ntldr/setupldr.c
boot/freeldr/freeldr/ntldr/winldr.c

index 20a7eff..68841f8 100644 (file)
@@ -191,6 +191,7 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem,
     UiDrawProgressBarCenter(1, 100, "Loading ReactOS Setup...");
 
     /* Read the system path is set in the .ini file */
+    BootPath[0] = ANSI_NULL;
     if (!HasSection || !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
     {
         /*
@@ -231,15 +232,23 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem,
     if ((strlen(BootPath) == 0) || BootPath[strlen(BootPath) - 1] != '\\')
         strcat(BootPath, "\\");
 
-    /* Read booting options */
+    /* Read boot options */
+    BootOptions2[0] = ANSI_NULL;
     if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions2, sizeof(BootOptions2)))
     {
-        /* Get options after the title */
+        /* Retrieve the options after the quoted title */
         PCSTR p = SettingsValue;
-        while (*p == ' ' || *p == '"')
-            p++;
-        while (*p != '\0' && *p != '"')
-            p++;
+
+        /* Trim any leading whitespace and quotes */
+        while (*p == ' ' || *p == '\t' || *p == '"')
+            ++p;
+        /* Skip all the text up to the first last quote */
+        while (*p != ANSI_NULL && *p != '"')
+            ++p;
+        /* Trim any trailing whitespace and quotes */
+        while (*p == ' ' || *p == '\t' || *p == '"')
+            ++p;
+
         strcpy(BootOptions2, p);
         TRACE("BootOptions: '%s'\n", BootOptions2);
     }
index d888634..e8e2eb2 100644 (file)
@@ -652,13 +652,13 @@ LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem,
 {
     ULONG_PTR SectionId;
     PCSTR SectionName = OperatingSystem->SystemPartition;
-    CHAR  SettingsValue[80];
+    PCHAR File;
+    BOOLEAN Success;
     BOOLEAN HasSection;
+    CHAR  SettingsValue[80];
     CHAR  BootPath[MAX_PATH];
     CHAR  FileName[MAX_PATH];
     CHAR  BootOptions[256];
-    PCHAR File;
-    BOOLEAN Success;
     PLOADER_PARAMETER_BLOCK LoaderBlock;
 
     /* Get OS setting value */
@@ -673,6 +673,7 @@ LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem,
     UiDrawProgressBarCenter(1, 100, "Loading NT...");
 
     /* Read the system path is set in the .ini file */
+    BootPath[0] = ANSI_NULL;
     if (!HasSection || !IniReadSettingByName(SectionId, "SystemPath", BootPath, sizeof(BootPath)))
     {
         strcpy(BootPath, SectionName);
@@ -704,15 +705,23 @@ LoadAndBootWindows(IN OperatingSystemItem* OperatingSystem,
     if ((BootPath[0] == 0) || BootPath[strlen(BootPath) - 1] != '\\')
         strcat(BootPath, "\\");
 
-    /* Read booting options */
+    /* Read boot options */
+    BootOptions[0] = ANSI_NULL;
     if (!HasSection || !IniReadSettingByName(SectionId, "Options", BootOptions, sizeof(BootOptions)))
     {
-        /* Get options after the title */
+        /* Retrieve the options after the quoted title */
         PCSTR p = SettingsValue;
-        while (*p == ' ' || *p == '"')
-            p++;
-        while (*p != '\0' && *p != '"')
-            p++;
+
+        /* Trim any leading whitespace and quotes */
+        while (*p == ' ' || *p == '\t' || *p == '"')
+            ++p;
+        /* Skip all the text up to the first last quote */
+        while (*p != ANSI_NULL && *p != '"')
+            ++p;
+        /* Trim any trailing whitespace and quotes */
+        while (*p == ' ' || *p == '\t' || *p == '"')
+            ++p;
+
         strcpy(BootOptions, p);
         TRACE("BootOptions: '%s'\n", BootOptions);
     }