Skip to content

Commit f0cd0fb

Browse files
committed
Print bound region when bound checking error occurs
1 parent 233e22f commit f0cd0fb

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/bcheck.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,9 @@ void * __bound_ptr_add(void *p, size_t offset)
559559
if (tree->is_invalid || addr + offset > tree->size) {
560560
POST_SEM ();
561561
if (print_warn_ptr_add)
562-
bound_warning("%p is outside of the region", p + offset);
562+
bound_warning("%p is outside of the region (0x%lx..0x%lx)",
563+
p + offset, (long)tree->start,
564+
(long)(tree->start + tree->size - 1));
563565
if (never_fatal <= 0)
564566
return INVALID_POINTER; /* return an invalid pointer */
565567
return p + offset;
@@ -605,7 +607,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \
605607
if (addr <= tree->size) { \
606608
if (tree->is_invalid || addr + offset + dsize > tree->size) { \
607609
POST_SEM (); \
608-
bound_warning("%p is outside of the region", p + offset); \
610+
bound_warning("%p is outside of the region (0x%lx..0x%lx)", \
611+
p + offset, (long)tree->start, \
612+
(long)(tree->start + tree->size - 1)); \
609613
if (never_fatal <= 0) \
610614
return INVALID_POINTER; /* return an invalid pointer */ \
611615
return p + offset; \
@@ -1105,11 +1109,9 @@ void __bound_init(size_t *p, int mode)
11051109
while (p[0] != 0) {
11061110
tree = splay_insert(p[0], p[1], tree);
11071111
#if BOUND_DEBUG
1108-
if (print_calls) {
1109-
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
1110-
__FILE__, __FUNCTION__,
1111-
(void *) p[0], (unsigned long) p[1]);
1112-
}
1112+
dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
1113+
__FILE__, __FUNCTION__,
1114+
(void *) p[0], (unsigned long) p[1]);
11131115
#endif
11141116
p += 2;
11151117
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
126_bound_global.c:11: at main: BCHECK: ........ is outside of the region
1+
126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)
22
126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access

0 commit comments

Comments
 (0)