From 253663678a2d634cdd5000e90579218a1ab23a31 Mon Sep 17 00:00:00 2001 From: Evan Green Date: Fri, 4 Nov 2016 15:34:58 -0700 Subject: [PATCH] Fixes for Cedric's static analysis notes. Issue #17. --- apps/efiboot/efiboot.c | 3 ++- apps/lib/chalk/cif.c | 1 + apps/setup/win32/io.c | 1 + apps/swiss/id.c | 16 ++++++++++++++-- apps/swiss/ls/ls.c | 12 ++++++++++-- apps/swiss/ps.c | 21 +++++++++++++++++++++ apps/swiss/ssdaemon.c | 2 ++ drivers/dma/bcm2709/dmab2709.c | 2 -- kernel/armv7/prochw.c | 2 +- uefi/plat/panda/init/clock.c | 8 +++++++- uefi/plat/veyron/fwbuild/fwbuild.c | 4 ++++ 11 files changed, 63 insertions(+), 9 deletions(-) diff --git a/apps/efiboot/efiboot.c b/apps/efiboot/efiboot.c index d4d5d6ee..346272ee 100644 --- a/apps/efiboot/efiboot.c +++ b/apps/efiboot/efiboot.c @@ -553,7 +553,8 @@ Return Value: if ((VariableDataSize % sizeof(UINT16)) != 0) { fprintf(stderr, "efiboot: Warning: BootOrder variable size was %d, not a " - "multiple of 2!\n"); + "multiple of 2!\n", + VariableDataSize); } Count = VariableDataSize / sizeof(UINT16); diff --git a/apps/lib/chalk/cif.c b/apps/lib/chalk/cif.c index 9a616a98..c5b500c0 100644 --- a/apps/lib/chalk/cif.c +++ b/apps/lib/chalk/cif.c @@ -1006,6 +1006,7 @@ Return Value: Count += 1; } + va_end(ArgumentList); Status = ChalkExecuteFunction(Interpreter, Function, List, ReturnValue); CExecuteFunctionEnd: diff --git a/apps/setup/win32/io.c b/apps/setup/win32/io.c index 24ed63b7..4dc26265 100644 --- a/apps/setup/win32/io.c +++ b/apps/setup/win32/io.c @@ -244,6 +244,7 @@ Return Value: PathCopy = strdup(Destination->Path); if (PathCopy == NULL) { + free(IoHandle); return NULL; } diff --git a/apps/swiss/id.c b/apps/swiss/id.c index 91501a31..f3672b17 100644 --- a/apps/swiss/id.c +++ b/apps/swiss/id.c @@ -490,7 +490,13 @@ Return Value: if (((Options & ID_OPTION_EXCLUSIVE_MASK) == 0) || ((Options & ID_OPTION_PRINT_NAMES) != 0)) { - SwGetUserNameFromId(UserId, &UserName); + if (SwGetUserNameFromId(UserId, &UserName) != 0) { + + assert(UserName == NULL); + + printf("%u", (unsigned int)UserId); + return; + } } // @@ -558,7 +564,13 @@ Return Value: if (((Options & ID_OPTION_EXCLUSIVE_MASK) == 0) || ((Options & ID_OPTION_PRINT_NAMES) != 0)) { - SwGetGroupNameFromId(GroupId, &GroupName); + if (SwGetGroupNameFromId(GroupId, &GroupName) != 0) { + + assert(GroupName == NULL); + + printf("%u", (unsigned int)GroupId); + return; + } } // diff --git a/apps/swiss/ls/ls.c b/apps/swiss/ls/ls.c index 6295f0c0..4a74d742 100644 --- a/apps/swiss/ls/ls.c +++ b/apps/swiss/ls/ls.c @@ -2130,8 +2130,16 @@ Return Value: if (((Context->Flags & LS_OPTION_LONG_FORMAT) != 0) && ((Context->Flags & LS_OPTION_PRINT_USER_GROUP_NUMBERS) == 0)) { - SwGetUserNameFromId(Stat->st_uid, &(NewFile->OwnerName)); - SwGetGroupNameFromId(Stat->st_gid, &(NewFile->GroupName)); + if (SwGetUserNameFromId(Stat->st_uid, &(NewFile->OwnerName)) != 0) { + + assert(NewFile->OwnerName == NULL); + } + + if (SwGetGroupNameFromId(Stat->st_gid, &(NewFile->GroupName)) != + 0) { + + assert(NewFile->GroupName == NULL); + } } } else { diff --git a/apps/swiss/ps.c b/apps/swiss/ps.c index 25a70d8e..419017c9 100644 --- a/apps/swiss/ps.c +++ b/apps/swiss/ps.c @@ -1545,6 +1545,9 @@ Return Value: case PsDataEffectiveUserIdentifier: Result = SwGetUserNameFromId(Information->EffectiveUserId, &StringData); if (Result != 0) { + + assert(StringData == NULL); + DataAvailable = FALSE; break; } @@ -1555,6 +1558,9 @@ Return Value: case PsDataRealUserIdentifier: Result = SwGetUserNameFromId(Information->RealUserId, &StringData); if (Result != 0) { + + assert(StringData == NULL); + DataAvailable = FALSE; break; } @@ -1565,6 +1571,9 @@ Return Value: case PsDataRealGroupIdentifier: Result = SwGetGroupNameFromId(Information->RealGroupId, &StringData); if (Result != 0) { + + assert(StringData == NULL); + DataAvailable = FALSE; break; } @@ -1577,6 +1586,9 @@ Return Value: &StringData); if (Result != 0) { + + assert(StringData == NULL); + DataAvailable = FALSE; break; } @@ -2131,6 +2143,9 @@ Return Value: &GroupName); if (Result != 0) { + + assert(GroupName == NULL); + continue; } } @@ -2237,6 +2252,9 @@ Return Value: &UserName); if (Result != 0) { + + assert(UserName == NULL); + continue; } } @@ -2283,6 +2301,9 @@ Return Value: &UserName); if (Result != 0) { + + assert(UserName == NULL); + continue; } } diff --git a/apps/swiss/ssdaemon.c b/apps/swiss/ssdaemon.c index 80cc66c9..06e94111 100644 --- a/apps/swiss/ssdaemon.c +++ b/apps/swiss/ssdaemon.c @@ -932,9 +932,11 @@ Return Value: } if (fscanf(File, "%u", &ScannedPid) != 1) { + fclose(File); return EINVAL; } + fclose(File); SsDaemonMatchPid(Context, ScannedPid); return 0; } diff --git a/drivers/dma/bcm2709/dmab2709.c b/drivers/dma/bcm2709/dmab2709.c index 24b59b2d..5f19a23d 100644 --- a/drivers/dma/bcm2709/dmab2709.c +++ b/drivers/dma/bcm2709/dmab2709.c @@ -1376,7 +1376,6 @@ Return Value: PHYSICAL_ADDRESS PreviousAddress; PDMA_BCM2709_CONTROL_BLOCK PreviousControlBlock; UINTN Remaining; - UINTN Size; KSTATUS Status; UINTN TransferSize; @@ -1508,7 +1507,6 @@ Return Value: FragmentOffset = 0; } - Size += BytesThisRound; TransferSize += BytesThisRound; Remaining -= BytesThisRound; PreviousAddress += BytesThisRound; diff --git a/kernel/armv7/prochw.c b/kernel/armv7/prochw.c index e3f43a44..d7cb98fc 100644 --- a/kernel/armv7/prochw.c +++ b/kernel/armv7/prochw.c @@ -128,6 +128,7 @@ Return Value: } ExceptionStacks = ArP0ExceptionStacks; + InterruptTable = ArP0InterruptTable; if (PhysicalMode == FALSE) { // @@ -135,7 +136,6 @@ Return Value: // subsystem is not yet online. // - InterruptTable = ArP0InterruptTable; if (ProcessorStructures == NULL) { ProcessorBlock = &ArP0ProcessorBlock; diff --git a/uefi/plat/panda/init/clock.c b/uefi/plat/panda/init/clock.c index 552d1473..8888f406 100644 --- a/uefi/plat/panda/init/clock.c +++ b/uefi/plat/panda/init/clock.c @@ -632,7 +632,13 @@ Return Value: UINT32 Mask; UINT32 Register; - Mask = 1 << BitCount; + if (BitCount == 32) { + Mask = 0; + + } else { + Mask = 1 << BitCount; + } + Mask -= 1; Register = OMAP4_READ32(Address) & ~(Mask << StartBit); Register |= Value << StartBit; diff --git a/uefi/plat/veyron/fwbuild/fwbuild.c b/uefi/plat/veyron/fwbuild/fwbuild.c index e01be007..15496b8c 100644 --- a/uefi/plat/veyron/fwbuild/fwbuild.c +++ b/uefi/plat/veyron/fwbuild/fwbuild.c @@ -456,6 +456,10 @@ Return Value: fclose(FirmwareImage); } + if (KeyBlockFile != NULL) { + fclose(KeyBlockFile); + } + if (FirmwareImageBuffer != NULL) { free(FirmwareImageBuffer); }