1
0

heap_tainted_memory.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "string.h"
  2. #include "private.h"
  3. #include "context.h"
  4. /* flag to indicate whether to taint memory or not */
  5. static bool_t tainted = BOOL_FALSE;
  6. /*--------------------------------------------------------- */
  7. bool_t lub_heap_taint(bool_t enable)
  8. {
  9. bool_t result = tainted;
  10. tainted = enable;
  11. return result;
  12. }
  13. /*--------------------------------------------------------- */
  14. bool_t lub_heap_is_tainting(void)
  15. {
  16. return tainted;
  17. }
  18. /*--------------------------------------------------------- */
  19. void lub_heap_taint_memory(char *ptr, lub_heap_taint_t type, size_t size)
  20. {
  21. if (BOOL_TRUE == tainted) {
  22. #ifdef __vxworks
  23. extern function_t taskDestroy; /* fiddle a reference to the function ... */
  24. extern function_t taskSuspend; /* ...and the next function in the library */
  25. /*
  26. * VxWorks taskDestroy() relies on being able to access
  27. * free memory.
  28. * It calls objFree() followed by objTerminate() !!!!
  29. * So we have to perform a crufty hack to avoid this
  30. * mistake blowing us out of the water...
  31. */
  32. if (LUB_HEAP_TAINT_FREE == type) {
  33. int i;
  34. /* obtain the backtrace of the stack */
  35. stackframe_t frame;
  36. lub_heap__get_stackframe(&frame, 10);
  37. for (i = 0; i < 10; i++) {
  38. function_t *address = frame.backtrace[i];
  39. if ((address > &taskDestroy)
  40. && (address < &taskSuspend)) {
  41. return;
  42. }
  43. }
  44. }
  45. #endif /* __vxworks */
  46. /* taint the memory */
  47. memset(ptr, type, size);
  48. }
  49. }
  50. /*--------------------------------------------------------- */