From 224b1cc286122b8aca5002fec31ed0390b299403 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 26 Sep 2016 07:42:24 +0200 Subject: Fix various issues reported by Coverity --- DcsCfg/DcsCfgCrypt.c | 26 ++++++++++++++++++++------ DcsCfg/DcsCfgMain.c | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'DcsCfg') diff --git a/DcsCfg/DcsCfgCrypt.c b/DcsCfg/DcsCfgCrypt.c index 4dab9bc..d031dcb 100644 --- a/DcsCfg/DcsCfgCrypt.c +++ b/DcsCfg/DcsCfgCrypt.c @@ -880,7 +880,13 @@ BlockRangeWipe( pos = start; do { rd = (UINTN)((remains > CRYPT_BUF_SECTORS) ? CRYPT_BUF_SECTORS : remains); - RandgetBytes(buf, (UINT32)(rd << 9), FALSE); + + if (!RandgetBytes(buf, (UINT32)(rd << 9), FALSE)) { + ERR_PRINT(L"No randoms. Wipe stopped.\n"); + res = EFI_CRC_ERROR; + MEM_FREE(buf); + return res; + } res = bio->WriteBlocks(bio, bio->Media->MediaId, pos, rd << 9, buf); if (EFI_ERROR(res)) { ERR_PRINT(L"Write error: %r\n", res); @@ -892,6 +898,7 @@ BlockRangeWipe( OUT_PRINT(L"%lld %lld \r", pos, remains); } while (remains > 0); OUT_PRINT(L"\nDone\n", pos, remains); + MEM_FREE(buf); return res; } @@ -1077,11 +1084,18 @@ UpdateDcsBoot() { DevicePath = DevicePathFromHandle(hDisk); len = GetDevicePathSize(DevicePath); // res = EfiSetVar(DCS_BOOT_STR, NULL, DevicePath, len, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS); - FileSave(NULL, DCS_BOOT_STR, DevicePath, len); - OUT_PRINT(L"Boot:"); - EfiPrintDevicePath(hDisk); - OUT_PRINT(L"\n"); - } + res = FileSave(NULL, DCS_BOOT_STR, DevicePath, len); + if (EFI_ERROR(res)) { + OUT_PRINT(L" %r\n", res); + return; + } + else + { + OUT_PRINT(L"Boot:"); + EfiPrintDevicePath(hDisk); + OUT_PRINT(L"\n"); + } + } OUT_PRINT(L" %r\n", res); } diff --git a/DcsCfg/DcsCfgMain.c b/DcsCfg/DcsCfgMain.c index 5c2ce2b..59ff730 100644 --- a/DcsCfg/DcsCfgMain.c +++ b/DcsCfg/DcsCfgMain.c @@ -350,8 +350,8 @@ DcsCfgMain( res = EFI_BUFFER_TOO_SMALL; temp = MEM_ALLOC(size); if (temp == NULL || - EFI_ERROR(res = RndGetBytes(temp, size) || - EFI_ERROR(res = FileSave(NULL, (CHAR16*)optFile, temp, size))) + EFI_ERROR(res = RndGetBytes(temp, size)) || + EFI_ERROR(res = FileSave(NULL, (CHAR16*)optFile, temp, size)) ) { ERR_PRINT(L"Random: %r\n", res); } -- cgit v1.2.3