Skip to content

Commit

Permalink
[PAL] Fix main() signature in regression tests for UBSan
Browse files Browse the repository at this point in the history
Newer Clang versions (v18 and newer) added more UBSan checks that
triggered UBSan on PAL regression tests. For more info, see commit
78776a5 ("[common] Update UBSan to be compatible with Clang 18").

Signed-off-by: Wojtek Porczyk <[email protected]>
  • Loading branch information
woju committed Sep 23, 2024
1 parent f5bfa34 commit 76a010e
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 17 deletions.
6 changes: 5 additions & 1 deletion pal/regression/AttestationReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

char zerobuf[sizeof(sgx_report_t)] = {0};

int main(int argc, char** argv) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(envp);

int ret;

size_t user_report_data_size;
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/Event.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ static noreturn int thread_func(void* arg) {
PalThreadExit(&g_clear_thread_exit);
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

PAL_HANDLE event = NULL;
CHECK(PalEventCreate(&event, /*init_signaled=*/true, /*auto_clear=*/true));

Expand Down
8 changes: 7 additions & 1 deletion pal/regression/Exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ static void handler4(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
context->rip++;
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

pal_printf("Stack in main: %p\n", get_stack());

PalSetExceptionHandler(handler1, PAL_EVENT_ARITHMETIC_ERROR);
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/Exception2.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ static void handler(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* context) {
PalProcessExit(0);
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

pal_printf("Enter Main Thread\n");

PalSetExceptionHandler(handler, PAL_EVENT_ARITHMETIC_ERROR);
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/Hex.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ char y[] = {0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd};
static_assert(sizeof(x) <= sizeof(y), "array x is longer than array y");
char hex_buf[sizeof(y) * 2 + 1];

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

pal_printf("Hex test 1 is %s\n", bytes2hex(x, sizeof(x), hex_buf, sizeof(hex_buf)));
pal_printf("Hex test 2 is %s\n", bytes2hex(y, sizeof(y), hex_buf, sizeof(hex_buf)));
return 0;
Expand Down
2 changes: 1 addition & 1 deletion pal/regression/Misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "pal_error.h"
#include "pal_regression.h"

int main(int argc, const char** argv, const char** envp) {
int main(int argc, char** argv, char** envp) {
uint64_t time1 = 0;
if (PalSystemTimeQuery(&time1) < 0) {
pal_printf("PalSystemTimeQuery failed\n");
Expand Down
6 changes: 5 additions & 1 deletion pal/regression/Process4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#include "pal.h"
#include "pal_regression.h"

int main(int argc, char** argv) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(envp);

int count = 0;

pal_printf("In process: %s", argv[0]);
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/Thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ static noreturn int callback(void* args) {
/* UNREACHABLE */
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

if (PalSegmentBaseSet(PAL_SEGMENT_FS, (uintptr_t)&private1) < 0) {
pal_printf("Failed to set FS\n");
return 1;
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/Thread2.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ static int thread4_run(void* args) {

// If there's a thread limit, like on SGX, it should be set to exactly 2. There
// should be only the main thread and only one other thread at a time.
int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

pal_printf("Thread 1 (main) started.\n");

PAL_HANDLE sleep_handle = NULL;
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/avl_tree_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,13 @@ static int32_t rand_mod(void) {
return rand() % (ELEMENTS_COUNT / 4);
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

pal_printf("Running static tests: ");
test_ordering();
srand(1337);
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/ipv4_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ static int ipv4_invalid(const char* buf) {
return 0;
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

CHECK(ipv4_valid("255.255.255.255", 0xffffffff));
CHECK(ipv4_valid("8.8.8.8", 0x08080808));
CHECK(ipv4_valid("8.8.8.8 with suffix", 0x08080808));
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/ipv6_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ static int ipv6_invalid(const char* buf) {
return 0;
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

struct {
const char* str;
uint16_t addr[8];
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ static void memfault_handler(bool is_in_pal, uintptr_t addr, PAL_CONTEXT* contex
/* Disable AddressSanitizer: this code tries to trigger a memory fault by accessing memory that's
* supposed to be inaccessible, but SGX PAL poisons such memory. */
__attribute_no_sanitize_address
int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

size_t total_mem = PalGetPalPublicState()->mem_total;
if (total_mem == 0) {
log_error("no memory???");
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/normalize_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ static int run_test(void) {
return 0;
}

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

cases = get_norm_path_cases;
cases_len = ARRAY_SIZE(get_norm_path_cases);
func_to_test = get_norm_path;
Expand Down
8 changes: 7 additions & 1 deletion pal/regression/printf_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
} \
})

int main(void) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(argc);
__UNUSED(argv);
__UNUSED(envp);

char* ptr = NULL;

/* Basic tests. */
Expand Down
6 changes: 5 additions & 1 deletion pal/regression/send_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ static void do_child(void) {
PalObjectDestroy(handle);
}

int main(int argc, char* argv[]) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(envp);

if (argc <= 0) {
pal_printf("Invalid argc: %d\n", argc);
return 1;
Expand Down
6 changes: 5 additions & 1 deletion pal/regression/strtoll_test.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "api.h"
#include "pal_regression.h"

int main(int argc, const char** argv) {
int main(int argc, char** argv, char** envp) {
/* We don't care about unused args to main, but UBSan complains otherwise
* with "call through pointer with incorrect function type" */
__UNUSED(envp);

const char* ptr = "123 asd";
const char* next = ptr;

Expand Down

0 comments on commit 76a010e

Please sign in to comment.