Skip to content

Commit

Permalink
mubsan: create test
Browse files Browse the repository at this point in the history
  • Loading branch information
xyve7 committed Sep 24, 2023
1 parent dc3458b commit 33f5d46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
16 changes: 8 additions & 8 deletions mubsan.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void __ubsan_handle_type_mismatch_v1(mubsan_type_mismatch_info_v1* data, uintptr
reason = "use of a misaligned pointer";
}

mubsan_log("mubsan: %s in %s, line %u, column %u, %s %s at alignment %u at address 0x%lx\n",
mubsan_log("%s in %s, line %u, column %u, %s %s at alignment %u at address 0x%lx\n",
reason,
data->loc.file,
data->loc.line,
Expand All @@ -69,7 +69,7 @@ void __ubsan_handle_type_mismatch_v1(mubsan_type_mismatch_info_v1* data, uintptr
ptr);
}
void __ubsan_handle_add_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t rhs) {
mubsan_log("mubsan: addition overflow in %s, line %u, column %u, %s %lu + %lu\n",
mubsan_log("addition overflow in %s, line %u, column %u, %s %lu + %lu\n",
data->loc.file,
data->loc.line,
data->loc.col,
Expand All @@ -78,7 +78,7 @@ void __ubsan_handle_add_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t
rhs);
}
void __ubsan_handle_sub_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t rhs) {
mubsan_log("mubsan: subtraction overflow in %s, line %u, column %u, %s %lu - %lu\n",
mubsan_log("subtraction overflow in %s, line %u, column %u, %s %lu - %lu\n",
data->loc.file,
data->loc.line,
data->loc.col,
Expand All @@ -87,7 +87,7 @@ void __ubsan_handle_sub_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t
rhs);
}
void __ubsan_handle_mul_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t rhs) {
mubsan_log("mubsan: multiplication overflow in %s, line %u, column %u, %s %lu * %lu\n",
mubsan_log("multiplication overflow in %s, line %u, column %u, %s %lu * %lu\n",
data->loc.file,
data->loc.line,
data->loc.col,
Expand All @@ -96,15 +96,15 @@ void __ubsan_handle_mul_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t
rhs);
}
void __ubsan_handle_negate_overflow(mubsan_overflow* data, uintptr_t val) {
mubsan_log("mubsan: addition overflow in %s, line %u, column %u, %s %lu\n",
mubsan_log("addition overflow in %s, line %u, column %u, %s %lu\n",
data->loc.file,
data->loc.line,
data->loc.col,
data->type->name,
val);
}
void __ubsan_handle_divrem_overflow(mubsan_overflow* data, uintptr_t lhs, uintptr_t rhs) {
mubsan_log("mubsan: division overflow in %s, line %u, column %u, %s %lu / %lu\n",
mubsan_log("division overflow in %s, line %u, column %u, %s %lu / %lu\n",
data->loc.file,
data->loc.line,
data->loc.col,
Expand All @@ -113,15 +113,15 @@ void __ubsan_handle_divrem_overflow(mubsan_overflow* data, uintptr_t lhs, uintpt
rhs);
}
void __ubsan_handle_pointer_overflow(mubsan_pointer_overflow* data, uintptr_t base, uintptr_t result) {
mubsan_log("mubsan: pointer overflow in %s, line %u, column %u, base=0x%lx, result=0x%lx\n",
mubsan_log("pointer overflow in %s, line %u, column %u, base=0x%lx, result=0x%lx\n",
data->loc.file,
data->loc.line,
data->loc.col,
base,
result);
}
void __ubsan_handle_out_of_bounds(mubsan_out_of_bounds* data, uintptr_t index) {
mubsan_log("mubsan: array out of bounds in %s, line %u, column %u, %s at %s %lu\n",
mubsan_log("array out of bounds in %s, line %u, column %u, %s at %s %lu\n",
data->loc.file,
data->loc.line,
data->loc.col,
Expand Down
17 changes: 16 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

int mubsan_log(const char* format, ...) {
va_list args;
va_start(args, format);

fprintf(stderr, "mubsan: ");
vfprintf(stderr, format, args);

va_end(args);

exit(1);
}

int main() {
int arr[4] = {1, 2, 3, 4};
arr[4] = 10;
}

0 comments on commit 33f5d46

Please sign in to comment.