OcMachoLib: Fix MachoGetNextSegment64() to return NULL when the LC is too small.
@@ -426,14 +426,16 @@ MachoGetNextSegment64 (
(CONST MACH_LOAD_COMMAND *)Segment
)
);
- if ((NextSegment != NULL)
- && (NextSegment->CommandSize >= sizeof (*NextSegment))) {
+ if ((NextSegment == NULL)
+ || (NextSegment->CommandSize < sizeof (*NextSegment))) {
+ return NULL;
+ }
+
TopOfSections = (UINTN)&NextSegment[NextSegment->NumSections];
if (((NextSegment->FileOffset + NextSegment->FileSize) > Context->FileSize)
|| (((UINTN)NextSegment + NextSegment->CommandSize) < TopOfSections)) {
return NULL;
}
- }
return NextSegment;
}
