From 8bde4de2d6ad0a768574334c035de83604a2e821 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bi=C8=99oc=20George?= Date: Sun, 10 Feb 2019 16:43:51 +0100 Subject: [PATCH] [USETUP][REACTOS] Check the status return value of InitDestinationPaths() (#1264) - Within the function's body code, check the status values returned by the called functions. - Change the BuildInstallPaths's function type to NTSTATUS instead of VOID (and check the status of InitDestinationPaths() as well. --- base/setup/lib/setuplib.c | 98 +++++++++++++++++++++++++++------- base/setup/reactos/drivepage.c | 10 +++- base/setup/usetup/usetup.c | 12 +++-- 3 files changed, 96 insertions(+), 24 deletions(-) diff --git a/base/setup/lib/setuplib.c b/base/setup/lib/setuplib.c index 2b52c463f37..9e4d22ee372 100644 --- a/base/setup/lib/setuplib.c +++ b/base/setup/lib/setuplib.c @@ -628,18 +628,29 @@ InitDestinationPaths( IN PPARTENTRY PartEntry) // FIXME: HACK! { WCHAR PathBuffer[MAX_PATH]; - - // - // TODO: Check return status values of the functions! - // + NTSTATUS Status; /* Create 'pSetupData->DestinationRootPath' string */ RtlFreeUnicodeString(&pSetupData->DestinationRootPath); - RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"\\Device\\Harddisk%lu\\Partition%lu\\", - DiskEntry->DiskNumber, - PartEntry->PartitionNumber); - RtlCreateUnicodeString(&pSetupData->DestinationRootPath, PathBuffer); + Status = RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"\\Device\\Harddisk%lu\\Partition%lu\\", + DiskEntry->DiskNumber, + PartEntry->PartitionNumber); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlStringCchPrintfW() failed with status 0x%08lx\n", Status); + return Status; + } + + Status = RtlCreateUnicodeString(&pSetupData->DestinationRootPath, PathBuffer) ? STATUS_SUCCESS : STATUS_NO_MEMORY; + + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlCreateUnicodeString() failed with status 0x%08lx\n", Status); + return Status; + } + DPRINT("DestinationRootPath: %wZ\n", &pSetupData->DestinationRootPath); // FIXME! Which variable to choose? @@ -649,23 +660,72 @@ InitDestinationPaths( /** Equivalent of 'NTOS_INSTALLATION::SystemArcPath' **/ /* Create 'pSetupData->DestinationArcPath' */ RtlFreeUnicodeString(&pSetupData->DestinationArcPath); - RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), - L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", - DiskEntry->BiosDiskNumber, - PartEntry->OnDiskPartitionNumber); - ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallationDir); - RtlCreateUnicodeString(&pSetupData->DestinationArcPath, PathBuffer); + Status = RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), + L"multi(0)disk(0)rdisk(%lu)partition(%lu)\\", + DiskEntry->BiosDiskNumber, + PartEntry->OnDiskPartitionNumber); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlStringCchPrintfW() failed with status 0x%08lx\n", Status); + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + return Status; + } + + Status = ConcatPaths(PathBuffer, ARRAYSIZE(PathBuffer), 1, InstallationDir); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("ConcatPaths() failed with status 0x%08lx\n", Status); + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + return Status; + } + + Status = RtlCreateUnicodeString(&pSetupData->DestinationArcPath, PathBuffer) ? STATUS_SUCCESS : STATUS_NO_MEMORY; + + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlCreateUnicodeString() failed with status 0x%08lx\n", Status); + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + return Status; + } /** Equivalent of 'NTOS_INSTALLATION::SystemNtPath' **/ /* Create 'pSetupData->DestinationPath' string */ RtlFreeUnicodeString(&pSetupData->DestinationPath); - CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, - pSetupData->DestinationRootPath.Buffer, InstallationDir); - RtlCreateUnicodeString(&pSetupData->DestinationPath, PathBuffer); + Status = CombinePaths(PathBuffer, ARRAYSIZE(PathBuffer), 2, + pSetupData->DestinationRootPath.Buffer, InstallationDir); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("CombinePaths() failed with status 0x%08lx\n", Status); + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + RtlFreeUnicodeString(&pSetupData->DestinationArcPath); + return Status; + } + + Status = RtlCreateUnicodeString(&pSetupData->DestinationPath, PathBuffer) ? STATUS_SUCCESS : STATUS_NO_MEMORY; + + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlCreateUnicodeString() failed with status 0x%08lx\n", Status); + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + RtlFreeUnicodeString(&pSetupData->DestinationArcPath); + return Status; + } /** Equivalent of 'NTOS_INSTALLATION::PathComponent' **/ // FIXME: This is only temporary!! Must be removed later! - /***/RtlCreateUnicodeString(&pSetupData->InstallPath, InstallationDir);/***/ + Status = RtlCreateUnicodeString(&pSetupData->InstallPath, InstallationDir) ? STATUS_SUCCESS : STATUS_NO_MEMORY; + + if (!NT_SUCCESS(Status)) + { + DPRINT1("RtlCreateUnicodeString() failed with status 0x%08lx\n", Status); + RtlFreeUnicodeString(&pSetupData->DestinationRootPath); + RtlFreeUnicodeString(&pSetupData->DestinationArcPath); + RtlFreeUnicodeString(&pSetupData->DestinationPath); + return Status; + } return STATUS_SUCCESS; } diff --git a/base/setup/reactos/drivepage.c b/base/setup/reactos/drivepage.c index a1b7d137bbf..b5f07b21d3f 100644 --- a/base/setup/reactos/drivepage.c +++ b/base/setup/reactos/drivepage.c @@ -33,6 +33,9 @@ #include "resource.h" +#define NDEBUG +#include + /* GLOBALS ******************************************************************/ #define IDS_LIST_COLUMN_FIRST IDS_PARTITION_NAME @@ -795,8 +798,11 @@ DisableWizNext: Status = InitDestinationPaths(&pSetupData->USetupData, NULL, // pSetupData->USetupData.InstallationDirectory, &DiskEntry, &PartEntry); - // TODO: Check Status - UNREFERENCED_PARAMETER(Status); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("InitDestinationPaths() failed with status 0x%08lx\n", Status); + } break; } diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 5aeb33697c7..a9a4f811743 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -3238,7 +3238,7 @@ CheckFileSystemPage(PINPUT_RECORD Ir) } -static VOID +static NTSTATUS BuildInstallPaths(PWSTR InstallDir, PDISKENTRY DiskEntry, PPARTENTRY PartEntry) @@ -3246,11 +3246,17 @@ BuildInstallPaths(PWSTR InstallDir, NTSTATUS Status; Status = InitDestinationPaths(&USetupData, InstallDir, DiskEntry, PartEntry); - // TODO: Check Status - UNREFERENCED_PARAMETER(Status); + + if (!NT_SUCCESS(Status)) + { + DPRINT1("InitDestinationPaths() failed with status 0x%08lx\n", Status); + return Status; + } /* Initialize DestinationDriveLetter */ DestinationDriveLetter = PartEntry->DriveLetter; + + return STATUS_SUCCESS; } -- 2.17.1