History

Print bound region when bound checking error occurs

herman ten brugge committed 2 years ago

Commit f0cd0fb1 parent 233e22f2 files · +10 −8Browse files

Unified · Split

2 files
  1. lib/bcheck.c +9 −7
  2. tests/tests2/126_bound_global.expect +1 −1
lib/bcheck.c+9−7
@@ -559,7 +559,9 @@ void * __bound_ptr_add(void *p, size_t offset) · 558 unmodified lines
559 if (tree->is_invalid || addr + offset > tree->size) {559 if (tree->is_invalid || addr + offset > tree->size) {
560 POST_SEM ();560 POST_SEM ();
561 if (print_warn_ptr_add)561 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));
563 if (never_fatal <= 0)565 if (never_fatal <= 0)
564 return INVALID_POINTER; /* return an invalid pointer */566 return INVALID_POINTER; /* return an invalid pointer */
565 return p + offset;567 return p + offset;
@@ -605,7 +607,9 @@ void * __bound_ptr_indir ## dsize (void *p, size_t offset) \ · 39 unmodified lines
605 if (addr <= tree->size) { \607 if (addr <= tree->size) { \
606 if (tree->is_invalid || addr + offset + dsize > tree->size) { \608 if (tree->is_invalid || addr + offset + dsize > tree->size) { \
607 POST_SEM (); \609 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)); \
609 if (never_fatal <= 0) \613 if (never_fatal <= 0) \
610 return INVALID_POINTER; /* return an invalid pointer */ \614 return INVALID_POINTER; /* return an invalid pointer */ \
611 return p + offset; \615 return p + offset; \
@@ -1105,11 +1109,9 @@ add_bounds: · 493 unmodified lines
1105 while (p[0] != 0) {1109 while (p[0] != 0) {
1106 tree = splay_insert(p[0], p[1], tree);1110 tree = splay_insert(p[0], p[1], tree);
1107#if BOUND_DEBUG1111#if BOUND_DEBUG
1108 if (print_calls) {1112 dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",
1109 dprintf(stderr, "%s, %s(): static var %p 0x%lx\n",1113 __FILE__, __FUNCTION__,
1110 __FILE__, __FUNCTION__,1114 (void *) p[0], (unsigned long) p[1]);
1111 (void *) p[0], (unsigned long) p[1]);
1112 }
1113#endif1115#endif
1114 p += 2;1116 p += 2;
1115 }1117 }
tests/tests2/126_bound_global.expect+1−1
@@ -1,2 +1,2 @@
1126_bound_global.c:11: at main: BCHECK: ........ is outside of the region1126_bound_global.c:11: at main: BCHECK: ........ is outside of the region (..................)
2126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access2126_bound_global.c:11: at main: RUNTIME ERROR: invalid memory access

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t