Small fixes to configuration parser
All checks were successful
Builds / ExectOS (i686) (push) Successful in 43s
Builds / ExectOS (amd64) (push) Successful in 45s

This commit is contained in:
Rafal Kupiec 2024-03-02 16:54:28 +01:00
parent d61fd4f9c7
commit 01983ef677
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4

View File

@ -46,7 +46,7 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName)
ValueLength = RtlWideStringLength(ConfigEntry->Value, 0); ValueLength = RtlWideStringLength(ConfigEntry->Value, 0);
/* Allocate memory for value */ /* Allocate memory for value */
Status = BlAllocateMemoryPool(ValueLength * sizeof(WCHAR), (PVOID *)&Value); Status = BlAllocateMemoryPool((ValueLength + 1) * sizeof(WCHAR), (PVOID *)&Value);
if(Status != STATUS_EFI_SUCCESS) if(Status != STATUS_EFI_SUCCESS)
{ {
/* Memory allocation failure, return NULL */ /* Memory allocation failure, return NULL */
@ -56,7 +56,7 @@ BlGetConfigValue(IN CONST PWCHAR ConfigName)
/* Copy value and return it */ /* Copy value and return it */
RtlCopyMemory(Value, ConfigEntry->Value, ValueLength * sizeof(WCHAR)); RtlCopyMemory(Value, ConfigEntry->Value, ValueLength * sizeof(WCHAR));
Value[ValueLength] = 0; Value[ValueLength] = L'\0';
return Value; return Value;
} }
@ -229,28 +229,28 @@ BlpParseCommandLine(VOID)
Key = Argument; Key = Argument;
/* Find end of the key */ /* Find end of the key */
while(*Argument != '=' && *Argument != 0 && *Argument != '\n') while(*Argument != L'=' && *Argument != L'\0' && *Argument != L'\n')
{ {
/* Advance to the next character */ /* Advance to the next character */
Argument++; Argument++;
} }
/* Mark end of the key and advance to the next character */ /* Mark end of the key and advance to the next character */
*Argument = 0; *Argument = L'\0';
Argument++; Argument++;
/* Store value */ /* Store value */
Value = Argument; Value = Argument;
/* Find end of the value */ /* Find end of the value */
while(*Argument != 0 && *Argument != '\n') while(*Argument != L'\0' && *Argument != L'\n')
{ {
/* Advance to the next character */ /* Advance to the next character */
Argument++; Argument++;
} }
/* Mark end of the value and advance to the next character */ /* Mark end of the value and advance to the next character */
*Argument = 0; *Argument = L'\0';
Argument++; Argument++;
/* Get length of the key and its value */ /* Get length of the key and its value */
@ -285,8 +285,8 @@ BlpParseCommandLine(VOID)
/* Set entry name and value */ /* Set entry name and value */
RtlCopyMemory(Option->Name, Key, (KeyLength * sizeof(WCHAR))); RtlCopyMemory(Option->Name, Key, (KeyLength * sizeof(WCHAR)));
RtlCopyMemory(Option->Value, Value, (ValueLength * sizeof(WCHAR))); RtlCopyMemory(Option->Value, Value, (ValueLength * sizeof(WCHAR)));
Option->Name[KeyLength] = 0; Option->Name[KeyLength] = L'\0';
Option->Value[ValueLength] = 0; Option->Value[ValueLength] = L'\0';
/* Add entry to the list */ /* Add entry to the list */
RtlInsertTailList(&Config, &Option->Flink); RtlInsertTailList(&Config, &Option->Flink);
@ -337,12 +337,12 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
Value = NULL; Value = NULL;
/* Analyze configuration data until end of file is reached */ /* Analyze configuration data until end of file is reached */
while(*InputData != 0) while(*InputData != '\0')
{ {
if(*InputData == ';' || *InputData == '#') if(*InputData == ';' || *InputData == '#')
{ {
/* Skip comment until end of the line */ /* Skip comment until end of the line */
while(*InputData != 0 && *InputData != '\n') while(*InputData != '\0' && *InputData != '\n')
{ {
/* Advance to the next character */ /* Advance to the next character */
InputData++; InputData++;
@ -362,7 +362,7 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
SectionName = InputData; SectionName = InputData;
/* Find end of the section name */ /* Find end of the section name */
while(*InputData != ']' && *InputData != 0 && *InputData != '\n') while(*InputData != ']' && *InputData != '\0' && *InputData != '\n')
{ {
/* Advance to the next character */ /* Advance to the next character */
InputData++; InputData++;
@ -376,7 +376,7 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
} }
/* Mark end of the section name and advance to the next character */ /* Mark end of the section name and advance to the next character */
*InputData = 0; *InputData = '\0';
InputData++; InputData++;
/* Remove leading and trailing spaces from section name */ /* Remove leading and trailing spaces from section name */
@ -398,9 +398,12 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
return Status; return Status;
} }
/* Initialize new section and add it to the list */ /* Initialize new section and convert its name to wide string */
RtlInitializeListHead(&Section->Options); RtlInitializeListHead(&Section->Options);
RtlStringToWideString(Section->SectionName, &SectionName, SectionLength + 1); RtlStringToWideString(Section->SectionName, &SectionName, SectionLength);
/* Ensure string is NULL-terminated and add new section to the configuration list */
Section->SectionName[SectionLength] = L'\0';
RtlInsertTailList(Configuration, &Section->Flink); RtlInsertTailList(Configuration, &Section->Flink);
} }
else else
@ -409,7 +412,7 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
Key = InputData; Key = InputData;
/* Find end of the key */ /* Find end of the key */
while(*InputData != '=' && *InputData != 0 && *InputData != '\n') while(*InputData != '=' && *InputData != '\0' && *InputData != '\n')
{ {
/* Advance to the next character */ /* Advance to the next character */
InputData++; InputData++;
@ -437,7 +440,7 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
Value = InputData; Value = InputData;
/* Find end of the value */ /* Find end of the value */
while(*InputData != 0 && *InputData != '\n') while(*InputData != '\0' && *InputData != '\n')
{ {
/* Advance to the next character */ /* Advance to the next character */
InputData++; InputData++;
@ -482,12 +485,16 @@ BlpParseConfigFile(IN CONST PCHAR RawConfig,
/* Remove trailing quotes from the value */ /* Remove trailing quotes from the value */
if(Value[ValueLength - 2] == '"' || Value[ValueLength - 2] == '\'') if(Value[ValueLength - 2] == '"' || Value[ValueLength - 2] == '\'')
{ {
Value[ValueLength - 2] = 0; Value[ValueLength - 2] = '\0';
} }
/* Initialize new option and add it to the list */ /* Convert key and value to wide strings */
RtlStringToWideString(Option->Name, &Key, RtlStringLength(Key, 0) + 1); RtlStringToWideString(Option->Name, &Key, RtlStringLength(Key, 0) + 1);
RtlStringToWideString(Option->Value, &Value, RtlStringLength(Value, 0) + 1); RtlStringToWideString(Option->Value, &Value, RtlStringLength(Value, 0) + 1);
/* Ensure strings are NULL-terminated and add new option to the list */
Option->Name[KeyLength] = L'\0';
Option->Value[ValueLength] = L'\0';
RtlInsertTailList(&Section->Options, &Option->Flink); RtlInsertTailList(&Section->Options, &Option->Flink);
} }
} }