mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 10:16:04 +02:00
FpDebug: Added some safety checks
git-svn-id: trunk@65144 -
This commit is contained in:
parent
60e0bbd0c7
commit
5191e4d8a2
@ -3000,6 +3000,8 @@ end;
|
|||||||
function TDwarfInformationEntry.DoReadReference(
|
function TDwarfInformationEntry.DoReadReference(
|
||||||
InfoIdx: Integer; InfoData: pointer; out AValue: Pointer; out
|
InfoIdx: Integer; InfoData: pointer; out AValue: Pointer; out
|
||||||
ACompUnit: TDwarfCompilationUnit): Boolean;
|
ACompUnit: TDwarfCompilationUnit): Boolean;
|
||||||
|
const
|
||||||
|
CU_HEADER_SIZE: array [boolean] of QWord = (SizeOf(TDwarfCUHeader32), SizeOf(TDwarfCUHeader64));
|
||||||
var
|
var
|
||||||
Form: Cardinal;
|
Form: Cardinal;
|
||||||
Offs: QWord;
|
Offs: QWord;
|
||||||
@ -3022,9 +3024,14 @@ begin
|
|||||||
if not Result then
|
if not Result then
|
||||||
exit;
|
exit;
|
||||||
ACompUnit := FCompUnit;
|
ACompUnit := FCompUnit;
|
||||||
if ACompUnit.FIsDwarf64
|
{$PUSH}{$R-}
|
||||||
then AValue := ACompUnit.FScope.Entry + Offs - SizeOf(TDwarfCUHeader64)
|
AValue := ACompUnit.FScope.Entry - CU_HEADER_SIZE[ACompUnit.FIsDwarf64] + Offs;
|
||||||
else AValue := ACompUnit.FScope.Entry + Offs - SizeOf(TDwarfCUHeader32);
|
{$POP}
|
||||||
|
if (AValue < ACompUnit.FInfoData) or (AValue >= ACompUnit.FInfoData + ACompUnit.FLength) then begin
|
||||||
|
DebugLn(FPDBG_DWARF_ERRORS, 'Error: Reference to invalid location. Offset %d is outsize the CU of size %d', [Offs, ACompUnit.FLength]);
|
||||||
|
AValue := nil;
|
||||||
|
Result := False;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if (Form = DW_FORM_ref_addr) then begin
|
if (Form = DW_FORM_ref_addr) then begin
|
||||||
@ -3554,6 +3561,7 @@ var
|
|||||||
CUClass: TDwarfCompilationUnitClass;
|
CUClass: TDwarfCompilationUnitClass;
|
||||||
inf: TDwarfSectionInfo;
|
inf: TDwarfSectionInfo;
|
||||||
i: integer;
|
i: integer;
|
||||||
|
DataOffs, DataLen: QWord;
|
||||||
begin
|
begin
|
||||||
CUClass := GetCompilationUnitClass;
|
CUClass := GetCompilationUnitClass;
|
||||||
for i := 0 to high(FFiles) do
|
for i := 0 to high(FFiles) do
|
||||||
@ -3567,11 +3575,17 @@ begin
|
|||||||
then begin
|
then begin
|
||||||
if CU64^.Version < 3 then
|
if CU64^.Version < 3 then
|
||||||
DebugLn(FPDBG_DWARF_WARNINGS, ['Unexpected 64 bit signature found for DWARF version 2']); // or version 1...
|
DebugLn(FPDBG_DWARF_WARNINGS, ['Unexpected 64 bit signature found for DWARF version 2']); // or version 1...
|
||||||
|
DataOffs := PtrUInt(CU64 + 1) - PtrUInt(inf.RawData);
|
||||||
|
DataLen := CU64^.Length - SizeOf(CU64^) + SizeOf(CU64^.Signature) + SizeOf(CU64^.Length);
|
||||||
|
if DataOffs + DataLen > inf.Size then begin
|
||||||
|
DebugLn(FPDBG_DWARF_ERRORS, 'Error: Invalid size for compilation unit at offest %d with size %d exceeds section size %d', [DataOffs, DataLen, inf.Size]);
|
||||||
|
break; // Do not process invalid data
|
||||||
|
end;
|
||||||
CU := CUClass.Create(
|
CU := CUClass.Create(
|
||||||
Self,
|
Self,
|
||||||
@FFiles[i],
|
@FFiles[i],
|
||||||
PtrUInt(CU64 + 1) - PtrUInt(inf.RawData),
|
DataOffs,
|
||||||
CU64^.Length - SizeOf(CU64^) + SizeOf(CU64^.Signature) + SizeOf(CU64^.Length),
|
DataLen,
|
||||||
CU64^.Version,
|
CU64^.Version,
|
||||||
CU64^.AbbrevOffset,
|
CU64^.AbbrevOffset,
|
||||||
CU64^.AddressSize,
|
CU64^.AddressSize,
|
||||||
@ -3580,11 +3594,17 @@ begin
|
|||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if CU32^.Length = 0 then Break;
|
if CU32^.Length = 0 then Break;
|
||||||
|
DataOffs := PtrUInt(CU32 + 1) - PtrUInt(inf.RawData);
|
||||||
|
DataLen := CU32^.Length - SizeOf(CU32^) + SizeOf(CU32^.Length);
|
||||||
|
if DataOffs + DataLen > inf.Size then begin
|
||||||
|
DebugLn(FPDBG_DWARF_ERRORS, 'Error: Invalid size for compilation unit at offest %d with size %d exceeds section size %d', [DataOffs, DataLen, inf.Size]);
|
||||||
|
break; // Do not process invalid data
|
||||||
|
end;
|
||||||
CU := CUClass.Create(
|
CU := CUClass.Create(
|
||||||
Self,
|
Self,
|
||||||
@FFiles[i],
|
@FFiles[i],
|
||||||
PtrUInt(CU32 + 1) - PtrUInt(inf.RawData),
|
DataOffs,
|
||||||
CU32^.Length - SizeOf(CU32^) + SizeOf(CU32^.Length),
|
DataLen,
|
||||||
CU32^.Version,
|
CU32^.Version,
|
||||||
CU32^.AbbrevOffset,
|
CU32^.AbbrevOffset,
|
||||||
CU32^.AddressSize,
|
CU32^.AddressSize,
|
||||||
|
Loading…
Reference in New Issue
Block a user