From f11fcd59a5aeac8647049d5746fe470a3b3725f3 Mon Sep 17 00:00:00 2001 From: xwashere Date: Thu, 11 Apr 2024 11:34:55 -0400 Subject: [PATCH] [lcrash/cckernel] FIX: "Properly" handle invalid locations in GzipDecompress, and other fixes. --- lcrash/CMakeLists.txt | 4 ++-- lcrash/acpi/acpi.c | 2 ++ lcrash/main.c | 2 +- lcrash/setup/compressed/elf.c | 2 +- lcrash/setup/compressed/gzip.c | 30 +++++++++++++++--------------- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lcrash/CMakeLists.txt b/lcrash/CMakeLists.txt index 84b0fe0..f61b95f 100644 --- a/lcrash/CMakeLists.txt +++ b/lcrash/CMakeLists.txt @@ -17,7 +17,7 @@ set_property(TARGET lcrashkern PROPERTY LINK_DEPENDS $ ) 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 ) diff --git a/lcrash/acpi/acpi.c b/lcrash/acpi/acpi.c index 9fdfef8..1ebbad2 100644 --- a/lcrash/acpi/acpi.c +++ b/lcrash/acpi/acpi.c @@ -73,4 +73,6 @@ void* AcpiGetTable(const char TableName[4]) { for (int i = 0; i < AcpiXSDTLength; i++) { } + + return 0; } diff --git a/lcrash/main.c b/lcrash/main.c index 1ef2047..4f9ab0a 100644 --- a/lcrash/main.c +++ b/lcrash/main.c @@ -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 diff --git a/lcrash/setup/compressed/elf.c b/lcrash/setup/compressed/elf.c index ad4cbd7..7bf360d 100644 --- a/lcrash/setup/compressed/elf.c +++ b/lcrash/setup/compressed/elf.c @@ -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); diff --git a/lcrash/setup/compressed/gzip.c b/lcrash/setup/compressed/gzip.c index 70badb6..7070a80 100644 --- a/lcrash/setup/compressed/gzip.c +++ b/lcrash/setup/compressed/gzip.c @@ -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); - u8 Flags = TAKE_(u8); - u32 LastModified = TAKE_(u32); - u8 ExtraFlags = TAKE_(u8); - u8 OperatingSystem = TAKE_(u8); + [[maybe_unused]] u8 Method = TAKE_(u8); + u8 Flags = 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;