https://git.reactos.org/?p=reactos.git;a=commitdiff;h=909bfff46049ff1309b564b04d0fe8c12fc02d19

commit 909bfff46049ff1309b564b04d0fe8c12fc02d19
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sun Aug 4 17:35:46 2019 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Sun Aug 4 17:47:04 2019 +0200

    [FREELDR] Some initialization fixes.
    
    - 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 | 21 +++++++++++++++------
 boot/freeldr/freeldr/ntldr/winldr.c   | 27 ++++++++++++++++++---------
 2 files changed, 33 insertions(+), 15 deletions(-)

diff --git a/boot/freeldr/freeldr/ntldr/setupldr.c 
b/boot/freeldr/freeldr/ntldr/setupldr.c
index 20a7eff355e..68841f8cda6 100644
--- a/boot/freeldr/freeldr/ntldr/setupldr.c
+++ b/boot/freeldr/freeldr/ntldr/setupldr.c
@@ -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);
     }
diff --git a/boot/freeldr/freeldr/ntldr/winldr.c 
b/boot/freeldr/freeldr/ntldr/winldr.c
index d888634da98..e8e2eb2fbff 100644
--- a/boot/freeldr/freeldr/ntldr/winldr.c
+++ b/boot/freeldr/freeldr/ntldr/winldr.c
@@ -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);
     }

Reply via email to