[PATCH] Add RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Jun 1 05:07:18 UTC 2018
An invalid heap usage such as a double free is usually a fatal error
since this indicates a use after free. Replace the use of printk() in
free() with a fatal error.
Update #3437.
---
cpukit/include/rtems/score/interr.h | 7 +++++++
cpukit/libcsupport/src/free.c | 7 +------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/cpukit/include/rtems/score/interr.h b/cpukit/include/rtems/score/interr.h
index 3144952716..f09072d5fb 100644
--- a/cpukit/include/rtems/score/interr.h
+++ b/cpukit/include/rtems/score/interr.h
@@ -131,6 +131,13 @@ typedef enum {
RTEMS_FATAL_SOURCE_PANIC = 11,
/**
+ * @brief Fatal source for invalid C program heap frees via free().
+ *
+ * The fatal code is the bad pointer.
+ */
+ RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE = 12,
+
+ /**
* @brief The last available fatal source.
*
* This enum value ensures that the enum type needs at least 32-bits for
diff --git a/cpukit/libcsupport/src/free.c b/cpukit/libcsupport/src/free.c
index 90209580db..d8dd2bdb0e 100644
--- a/cpukit/libcsupport/src/free.c
+++ b/cpukit/libcsupport/src/free.c
@@ -38,12 +38,7 @@ void free(
}
if ( !_Protected_heap_Free( RTEMS_Malloc_Heap, ptr ) ) {
- printk( "Program heap: free of bad pointer %p -- range %p - %p \n",
- ptr,
- (void*) RTEMS_Malloc_Heap->area_begin,
- (void*) RTEMS_Malloc_Heap->area_end
- );
+ rtems_fatal( RTEMS_FATAL_SOURCE_INVALID_HEAP_FREE, (rtems_fatal_code) ptr );
}
-
}
#endif
--
2.13.6
More information about the devel
mailing list