提交 079070a2 编写于 作者: D Download-Fritz

Fix several issues (Coverity, Clang)

上级 06448c85
......@@ -209,7 +209,7 @@ typedef struct {
RETURN_STATUS
ReadAppleKernel (
IN EFI_FILE_PROTOCOL *File,
IN OUT UINT8 **Kernel,
OUT UINT8 **Kernel,
OUT UINT32 *KernelSize,
OUT UINT32 *AllocatedSize,
IN UINT32 ReservedSize
......
......@@ -318,7 +318,7 @@ ReadAppleKernelImage (
RETURN_STATUS
ReadAppleKernel (
IN EFI_FILE_PROTOCOL *File,
IN OUT UINT8 **Kernel,
OUT UINT8 **Kernel,
OUT UINT32 *KernelSize,
OUT UINT32 *AllocatedSize,
IN UINT32 ReservedSize
......
......@@ -115,11 +115,12 @@ OcActivateHibernateWake (
DEBUG ((DEBUG_INFO, "OCB: boot-image is %u bytes - %r\n", (UINT32) Size, Status));
RtcRawVars = (UINT8 *) &RtcVars;
//
// Work with RTC memory if allowed.
//
if (HibernateMask & HIBERNATE_MODE_RTC) {
RtcRawVars = (UINT8 *) &RtcVars;
for (Index = 0; Index < sizeof (AppleRTCHibernateVars); Index++) {
RtcRawVars[Index] = OcRtcRead (Index + 128);
}
......
......@@ -207,7 +207,7 @@ RenderChar (
SetMem32 (DstBuffer, TGT_CHAR_AREA * sizeof (DstBuffer[0]), mBackgroundColor.Raw);
} else {
if (Char < ISO_CHAR_MIN || Char > ISO_CHAR_MAX) {
if (Char < 0 || Char > ISO_CHAR_MAX) {
Char = L'_';
}
......
......@@ -103,6 +103,12 @@ OcUnblockUnmountedPartitions (
DiskIoInfos[DiskIoInfoIndex].AgentHandle,
NULL
);
DEBUG ((
DEBUG_INFO,
"OCFSQ: Failed to unblock handle %p - %r\n",
Handles[HandleIndex],
Status
));
}
}
......
......@@ -1117,6 +1117,7 @@ MergeDefaultString (
(VOID *) (*AltCfgResp)
);
if (*AltCfgResp == NULL) {
*StringPtrEnd = TempChar;
FreePool (AltConfigHdr);
return EFI_OUT_OF_RESOURCES;
}
......
......@@ -50,10 +50,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define PROPORTIONAL_GLYPH 0x80
#define NARROW_GLYPH 0x40
#define BITMAP_LEN_1_BIT(Width, Height) (((Width) + 7) / 8 * (Height))
#define BITMAP_LEN_4_BIT(Width, Height) (((Width) + 1) / 2 * (Height))
#define BITMAP_LEN_8_BIT(Width, Height) ((Width) * (Height))
#define BITMAP_LEN_24_BIT(Width, Height) ((Width) * (Height) * 3)
#define BITMAP_LEN_1_BIT(Width, Height) (((UINT32) (Width) + 7) / 8 * (UINT32) (Height))
#define BITMAP_LEN_4_BIT(Width, Height) (((UINT32) (Width) + 1) / 2 * (UINT32) (Height))
#define BITMAP_LEN_8_BIT(Width, Height) ((UINT32) (Width) * (UINT32) (Height))
#define BITMAP_LEN_24_BIT(Width, Height) ((UINT32) (Width) * (UINT32) (Height) * 3)
extern EFI_LOCK mHiiDatabaseLock;
......
......@@ -151,7 +151,9 @@ BmfContextInitialize (
INT16 MinY;
UINT16 MaxY;
INT32 Height;
INT32 Width;
INT32 Advance;
CONST BMF_CHAR *Chars;
CONST BMF_KERNING_PAIR *Pairs;
......@@ -314,8 +316,26 @@ BmfContextInitialize (
MaxY = 0;
for (Index = 0; Index < Context->NumChars; ++Index) {
if ((INT32)Chars[Index].yoffset + (INT32)Chars[Index].height <= 0
|| Chars[Index].width < 0 || Chars[Index].xadvance < 0) {
Result = OcOverflowAddS32 (
Chars[Index].yoffset,
Chars[Index].height,
&Height
);
Result |= OcOverflowAddS32 (
Chars[Index].xoffset,
Chars[Index].width,
&Width
);
Result |= OcOverflowAddS32 (
Chars[Index].xoffset,
Chars[Index].xadvance,
&Advance
);
if (Result
|| 0 > Height || Height > MAX_UINT16
|| 0 > Width || Width > MAX_UINT16
|| 0 > Advance || Advance > MAX_UINT16
|| Chars[Index].xadvance < 0) {
DEBUG ((
DEBUG_WARN,
"BMF: Char insane\n"
......@@ -343,26 +363,8 @@ BmfContextInitialize (
return FALSE;
}
Result = OcOverflowAddS32 (
Chars[Index].xoffset,
Chars[Index].width,
&Width
);
if (Result || Width < 0) {
return FALSE;
}
Result = OcOverflowAddS32 (
Chars[Index].xoffset,
Chars[Index].xadvance,
&Width
);
if (Result || Width < 0) {
return FALSE;
}
MinY = MIN (MinY, Chars[Index].yoffset);
MaxY = MAX (MaxY, Chars[Index].yoffset + Chars[Index].height);
MaxY = MAX (MaxY, (UINT16) Height);
//
// This only yields unexpected but not undefined behaviour when not met,
// hence it is fine verifying it only DEBUG mode.
......@@ -380,14 +382,34 @@ BmfContextInitialize (
DEBUG_CODE_END ();
}
Context->Height = MaxY - MinY;
Result = OcOverflowSubS32 (
MaxY,
MinY,
&Height
);
if (Result
|| 0 >= Height || Height > MAX_UINT16) {
DEBUG ((
DEBUG_WARN,
"BMF: Insane font Y info %d %d\n",
MaxY,
MinY
));
return FALSE;
}
Context->Height = (UINT16) Height;
Context->OffsetY = -MinY;
Pairs = Context->KerningPairs;
for (Index = 0; Index < Context->NumKerningPairs; ++Index) {
Char = BmfGetChar (Context, Pairs[Index].first);
if (Char == NULL) {
DEBUG ((DEBUG_WARN, "BMF: Pair char not found\n"));
DEBUG ((
DEBUG_WARN,
"BMF: Pair char %u not found\n",
Pairs[Index].first
));
return FALSE;
}
......@@ -396,16 +418,24 @@ BmfContextInitialize (
Pairs[Index].amount,
&Width
);
if (Result || Width < 0) {
return FALSE;
}
Result = OcOverflowAddS32 (
Char->xoffset + Char->xadvance,
Pairs[Index].amount,
&Width
);
if (Result || Width < 0) {
Result |= OcOverflowAddS32 (
Char->xoffset + Char->xadvance,
Pairs[Index].amount,
&Advance
);
if (Result
|| 0 > Width || Width > MAX_UINT16
|| 0 > Advance || Advance > MAX_UINT16) {
DEBUG ((
DEBUG_WARN,
"BMF: Pair insane\n"
" first %u\n"
" second %u\n"
" amount %d\n",
Pairs[Index].first,
Pairs[Index].second,
Pairs[Index].amount
));
return FALSE;
}
//
......@@ -607,7 +637,7 @@ GuiGetLabel (
return FALSE;
}
Buffer = AllocateZeroPool (TextInfo->Width * TextInfo->Height * sizeof (*Buffer));
Buffer = AllocateZeroPool ((UINT32) TextInfo->Width * (UINT32) TextInfo->Height * sizeof (*Buffer));
if (Buffer == NULL) {
DEBUG ((DEBUG_WARN, "BMF: out of res\n"));
FreePool (TextInfo);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册