[lcrash/cckernel] FIX: "Properly" handle invalid locations in GzipDecompress, and other fixes.

This commit is contained in:
xwashere 2024-04-11 11:34:55 -04:00
parent cd237386e3
commit f11fcd59a5
Signed by: XWasHere
GPG Key ID: 042F8BFA1B0EF93B
5 changed files with 21 additions and 19 deletions

View File

@ -17,7 +17,7 @@ set_property(TARGET lcrashkern PROPERTY LINK_DEPENDS
$<TARGET_FILE:LindowsCompilerSpec>
)
set_property(TARGET lcrashkern PROPERTY LINK_OPTIONS -nostdlib -Wl,-T,${CMAKE_CURRENT_SOURCE_DIR}/lcrash.ld )
target_compile_options(lcrashkern PRIVATE -ggdb -fpic -pie -Wall -fanalyzer)
target_compile_options(lcrashkern PRIVATE -ggdb -fpic -pie -Wall -Werror -fanalyzer)
target_link_options(lcrashkern PRIVATE -fpic -pie)
target_include_directories(lcrashkern PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
@ -46,7 +46,7 @@ lw_add_executable(cckernel
add_executable(cckernelld IMPORTED)
set_property(TARGET cckernelld PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/setup/compressed/compressed.ld)
set_property(TARGET cckernel PROPERTY LINK_OPTIONS -nostdlib -Wl,-T,${CMAKE_CURRENT_SOURCE_DIR}/setup/compressed/compressed.ld)
target_compile_options(cckernel PRIVATE -ggdb -mno-sse -mno-avx -Wall -fanalyzer) # disable generating SIMD code since we haven't configured it at this stage of the boot thing
target_compile_options(cckernel PRIVATE -ggdb -mno-sse -mno-avx -Wall -Werror -fanalyzer) # disable generating SIMD code since we haven't configured it at this stage of the boot thing
set_property(SOURCE setup/compressed/cckernel.S PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/lcrashkern.gz
)

View File

@ -73,4 +73,6 @@ void* AcpiGetTable(const char TableName[4]) {
for (int i = 0; i < AcpiXSDTLength; i++) {
}
return 0;
}

View File

@ -16,7 +16,7 @@ void entry64(struct boot_params* BootParams) {
// Notify the debugger that we're ready
struct GdbDataBlock* GdbDataBlock = (struct GdbDataBlock*)0x100000;
GdbDataBlock->KernelLoaded = true;
GdbDataBlock->KernelBase = BootSetupInfo->code32_start;
GdbDataBlock->KernelBase = (void*)BootSetupInfo->code32_start;
GdbDataBlock->Update++;
// Initialize EFI code if we had EFI

View File

@ -39,7 +39,7 @@ void ElfExecute(void* Binary, void* LoadAddr, struct boot_params* BootParams) {
// Set boot parameters
struct setup_info* SetupInfo = (void*)BootParams + 0x1f1;
SetupInfo->code32_start = LoadAddr;
SetupInfo->code32_start = (u64)LoadAddr;
// Enter the kernel
KernelEntry(BootParams);

View File

@ -104,18 +104,18 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
// we dont even bother making sure it's valid, we have no way to tell
// the user there's something wrong
while (Location < End) {
c8 Id1 = TAKE_(c8);
c8 Id2 = TAKE_(c8);
[[maybe_unused]] c8 Id1 = TAKE_(c8);
[[maybe_unused]] c8 Id2 = TAKE_(c8);
u8 Method = TAKE_(u8);
[[maybe_unused]] u8 Method = TAKE_(u8);
u8 Flags = TAKE_(u8);
u32 LastModified = TAKE_(u32);
u8 ExtraFlags = TAKE_(u8);
u8 OperatingSystem = TAKE_(u8);
[[maybe_unused]] u32 LastModified = TAKE_(u32);
[[maybe_unused]] u8 ExtraFlags = TAKE_(u8);
[[maybe_unused]] u8 OperatingSystem = TAKE_(u8);
// for the magic extra field
u16 XLen = 0;
void* XBuf = 0;
[[maybe_unused]] u16 XLen = 0;
[[maybe_unused]] void* XBuf = 0;
if (Flags & 0x04) { // FLG.FEXTRA
XLen = TAKE_(u16);
XBuf = Location;
@ -123,21 +123,21 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
}
// filename
c8* FileName = 0;
[[maybe_unused]] c8* FileName = 0;
if (Flags & 0x08) { // FLG.FNAME
FileName = Location;
while (TAKE_(c8) != 0) {}
}
// comment
c8* FileComment = 0;
[[maybe_unused]] c8* FileComment = 0;
if (Flags & 0x10) { // FLG.FCOMMENT
FileComment = Location;
while (TAKE_(c8) != 0) {}
}
// hash
u16 CRC16 = 0;
[[maybe_unused]] u16 CRC16 = 0;
if (Flags & 0x02) { // FLG.FHCRC
CRC16 = TAKE_(u16);
}
@ -189,7 +189,7 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
if (Code == 16) {
RepeatCount = 3 + GzipFetchBits(Stream, &BitLocation, 2);
RepeatedLen = Lengths[CurrentLen - 1];
RepeatedLen = CurrentLen > 0 ? Lengths[CurrentLen - 1] : 0;
} else if (Code == 17) {
RepeatCount = 3 + GzipFetchBits(Stream, &BitLocation, 3);
} else if (Code == 18) {
@ -294,8 +294,8 @@ uptr GzipDecompress(c8* Input, uptr InputSize, c8* Output) {
Location += BitLocation / 8 + 1;
// trailer..? hey siri, what's the opposite of a header?
u32 CRC32 = TAKE_(u32);
u32 InputSize = TAKE_(u32);
[[maybe_unused]] u32 CRC32 = TAKE_(u32);
[[maybe_unused]] u32 InputSize = TAKE_(u32);
}
return (void*)Output - BinaryStart;