https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d924cb8271d478c16a76c3c746946d8d4cc6f0e2
commit d924cb8271d478c16a76c3c746946d8d4cc6f0e2 Author: Jérôme Gardou <jerome.gar...@reactos.org> AuthorDate: Thu Jun 17 18:19:04 2021 +0200 Commit: Jérôme Gardou <zefk...@users.noreply.github.com> CommitDate: Mon Jun 28 10:20:57 2021 +0200 [NTOS:CONFIG] Do not ignore Rtl*String functions return value CORE-17637 --- ntoskrnl/config/i386/cmhardwr.c | 137 ++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 61 deletions(-) diff --git a/ntoskrnl/config/i386/cmhardwr.c b/ntoskrnl/config/i386/cmhardwr.c index 4b7457d12ac..7bdd139ecbd 100644 --- a/ntoskrnl/config/i386/cmhardwr.c +++ b/ntoskrnl/config/i386/cmhardwr.c @@ -472,22 +472,27 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Convert it to Unicode */ RtlInitAnsiString(&TempString, CpuString); - RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); - - /* Add it to the registry */ - RtlInitUnicodeString(&ValueName, L"ProcessorNameString"); - Status = NtSetValueKey(KeyHandle, - &ValueName, - 0, - REG_SZ, - Data.Buffer, - Data.Length + sizeof(UNICODE_NULL)); - - /* ROS: Save a copy for bugzilla reporting */ - RtlCreateUnicodeString(&KeRosProcessorName, Data.Buffer); + if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE))) + { + /* Add it to the registry */ + RtlInitUnicodeString(&ValueName, L"ProcessorNameString"); + Status = NtSetValueKey(KeyHandle, + &ValueName, + 0, + REG_SZ, + Data.Buffer, + Data.Length + sizeof(UNICODE_NULL)); + + /* ROS: Save a copy for bugzilla reporting */ + if (!RtlCreateUnicodeString(&KeRosProcessorName, Data.Buffer)) + { + /* Do not fail for this */ + KeRosProcessorName.Length = 0; + } - /* Free the temporary buffer */ - RtlFreeUnicodeString(&Data); + /* Free the temporary buffer */ + RtlFreeUnicodeString(&Data); + } } /* Check if we had a Vendor ID */ @@ -495,19 +500,20 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Convert it to Unicode */ RtlInitAnsiString(&TempString, Prcb->VendorString); - RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); - - /* Add it to the registry */ - RtlInitUnicodeString(&ValueName, L"VendorIdentifier"); - Status = NtSetValueKey(KeyHandle, - &ValueName, - 0, - REG_SZ, - Data.Buffer, - Data.Length + sizeof(UNICODE_NULL)); - - /* Free the temporary buffer */ - RtlFreeUnicodeString(&Data); + if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE))) + { + /* Add it to the registry */ + RtlInitUnicodeString(&ValueName, L"VendorIdentifier"); + Status = NtSetValueKey(KeyHandle, + &ValueName, + 0, + REG_SZ, + Data.Buffer, + Data.Length + sizeof(UNICODE_NULL)); + + /* Free the temporary buffer */ + RtlFreeUnicodeString(&Data); + } } /* Check if we have features bits */ @@ -638,19 +644,20 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Convert it to Unicode */ RtlInitAnsiString(&TempString, Buffer); - RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); - - /* Write the date into the registry */ - RtlInitUnicodeString(&ValueName, L"SystemBiosDate"); - Status = NtSetValueKey(SystemHandle, - &ValueName, - 0, - REG_SZ, - Data.Buffer, - Data.Length + sizeof(UNICODE_NULL)); + if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE))) + { + /* Write the date into the registry */ + RtlInitUnicodeString(&ValueName, L"SystemBiosDate"); + Status = NtSetValueKey(SystemHandle, + &ValueName, + 0, + REG_SZ, + Data.Buffer, + Data.Length + sizeof(UNICODE_NULL)); - /* Free the string */ - RtlFreeUnicodeString(&Data); + /* Free the string */ + RtlFreeUnicodeString(&Data); + } if (BiosHandle) { @@ -672,7 +679,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc Data.Length + sizeof(UNICODE_NULL)); /* ROS: Save a copy for bugzilla reporting */ - RtlCreateUnicodeString(&KeRosBiosDate, Data.Buffer); + if (!RtlCreateUnicodeString(&KeRosBiosDate, Data.Buffer)) + KeRosBiosDate.Length = 0; /* Free the string */ RtlFreeUnicodeString(&Data); @@ -692,7 +700,9 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Convert to Unicode */ RtlInitAnsiString(&TempString, Buffer); - RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); + Status = RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); + if (!NT_SUCCESS(Status)) + break; /* Calculate the length of this string and copy it in */ Length = Data.Length + sizeof(UNICODE_NULL); @@ -732,7 +742,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc TotalLength); /* ROS: Save a copy for bugzilla reporting */ - RtlCreateUnicodeString(&KeRosBiosVersion, (PWCH)BiosVersion); + if (!RtlCreateUnicodeString(&KeRosBiosVersion, (PWCH)BiosVersion)) + KeRosBiosVersion.Length = 0; } } @@ -763,22 +774,24 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Convert it to Unicode */ RtlInitAnsiString(&TempString, Buffer); - RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); - - /* Write the date into the registry */ - RtlInitUnicodeString(&ValueName, L"VideoBiosDate"); - Status = NtSetValueKey(SystemHandle, - &ValueName, - 0, - REG_SZ, - Data.Buffer, - Data.Length + sizeof(UNICODE_NULL)); - - /* ROS: Save a copy for bugzilla reporting */ - RtlCreateUnicodeString(&KeRosVideoBiosDate, Data.Buffer); - - /* Free the string */ - RtlFreeUnicodeString(&Data); + if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE))) + { + /* Write the date into the registry */ + RtlInitUnicodeString(&ValueName, L"VideoBiosDate"); + Status = NtSetValueKey(SystemHandle, + &ValueName, + 0, + REG_SZ, + Data.Buffer, + Data.Length + sizeof(UNICODE_NULL)); + + /* ROS: Save a copy for bugzilla reporting */ + if (!RtlCreateUnicodeString(&KeRosVideoBiosDate, Data.Buffer)) + KeRosVideoBiosDate.Length = 0; + + /* Free the string */ + RtlFreeUnicodeString(&Data); + } } /* Get the Video BIOS Version */ @@ -790,7 +803,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc { /* Convert to Unicode */ RtlInitAnsiString(&TempString, Buffer); - RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE); + if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&Data, &TempString, TRUE))) + break; /* Calculate the length of this string and copy it in */ Length = Data.Length + sizeof(UNICODE_NULL); @@ -830,7 +844,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc TotalLength); /* ROS: Save a copy for bugzilla reporting */ - RtlCreateUnicodeString(&KeRosVideoBiosVersion, (PWCH)BiosVersion); + if (!RtlCreateUnicodeString(&KeRosVideoBiosVersion, (PWCH)BiosVersion)) + KeRosVideoBiosVersion.Length = 0; } }