Print bound region when bound checking error occurs

This commit is contained in:
herman ten brugge 2024-11-09 08:34:10 +01:00
parent 233e22f23d
commit f0cd0fbe1b
2 changed files with 10 additions and 8 deletions

View file

@ -559,7 +559,9 @@ void * __bound_ptr_add(void *p, size_t offset)
if (tree->is_invalid || addr + offset > tree->size) { if (tree->is_invalid || addr + offset > tree->size) {
POST_SEM (); POST_SEM ();
if (print_warn_ptr_add) if (print_warn_ptr_add)
bound_warning("%p is outside of the region", p + offset); bound_warning("%p is outside of the region (0x%lx..0x%lx)",
p + offset, (long)tree->start,
(long)(tree->start + tree->size - 1));
if (never_fatal <= 0) if (never_fatal <= 0)
return INVALID_POINTER; /* return an invalid pointer */ return INVALID_POINTER; /* return an invalid pointer */
return p + offset; return p + offset;
@ -605,7 +607,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \
if (addr <= tree->size) { \ if (addr <= tree->size) { \
if (tree->is_invalid || addr + offset + dsize > tree->size) { \ if (tree->is_invalid || addr + offset + dsize > tree->size) { \
POST_SEM (); \ POST_SEM (); \
bound_warning("%p is outside of the region", p + offset); \ bound_warning("%p is outside of the region (0x%lx..0x%lx)", \
p + offset, (long)tree->start, \
(long)(tree->start + tree->size - 1)); \
if (never_fatal <= 0) \ if (never_fatal <= 0) \
return INVALID_POINTER; /* return an invalid pointer */ \ return INVALID_POINTER; /* return an invalid pointer */ \
return p + offset; \ return p + offset; \
@ -1105,11 +1109,9 @@ add_bounds:
while (p[0] != 0) { while (p[0] != 0) {
tree = splay_insert(p[0], p[1], tree); tree = splay_insert(p[0], p[1], tree);
#if BOUND_DEBUG #if BOUND_DEBUG
if (print_calls) { dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n", __FILE__, __FUNCTION__,
__FILE__, __FUNCTION__, (void *) p[0], (unsigned long) p[1]);
(void *) p[0], (unsigned long) p[1]);
}
#endif #endif
p += 2; p += 2;
} }

View file

@ -1,2 +1,2 @@
126_bound_global.c:11: at main: BCHECK: ........ is outside of the region 126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)
126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access 126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access