Skip to content

Commit

Permalink
Print bound region when bound checking error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
hermantb committed Nov 9, 2024
1 parent 233e22f commit f0cd0fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions lib/bcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ void * __bound_ptr_add(void *p, size_t offset)
if (tree->is_invalid || addr + offset > tree->size) {
POST_SEM ();
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)
return INVALID_POINTER; /* return an invalid pointer */
return p + offset;
Expand Down Expand Up @@ -605,7 +607,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \
if (addr <= tree->size) { \
if (tree->is_invalid || addr + offset + dsize > tree->size) { \
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) \
return INVALID_POINTER; /* return an invalid pointer */ \
return p + offset; \
Expand Down Expand Up @@ -1105,11 +1109,9 @@ void __bound_init(size_t *p, int mode)
while (p[0] != 0) {
tree = splay_insert(p[0], p[1], tree);
#if BOUND_DEBUG
if (print_calls) {
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
__FILE__, __FUNCTION__,
(void *) p[0], (unsigned long) p[1]);
}
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
__FILE__, __FUNCTION__,
(void *) p[0], (unsigned long) p[1]);
#endif
p += 2;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests2/126_bound_global.expect
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f0cd0fb

Please sign in to comment.