Add basic use-after-free checking in limited places.
[ldk-java] / typescript_strings.py
index 84b27c5723a66521d7f737ac486313b1aac52cb2..d1449c2224fda58e24d142825847c5d150059110 100644 (file)
@@ -123,6 +123,7 @@ void free(void *ptr);
 #define FREE(p) if ((unsigned long)(p) > 1024) { free(p); }
 #define DO_ASSERT(a) (void)(a)
 #define CHECK(a)
+#define CHECK_ACCESS(p)
 """
         else:
             self.c_file_pfx = self.c_file_pfx + """
@@ -179,6 +180,16 @@ static void FREE(void* ptr) {
        __real_free(ptr);
 }
 
+static void CHECK_ACCESS(void* ptr) {
+       allocation* it = allocation_ll;
+       while (it->ptr != ptr) {
+               it = it->next;
+               if (it == NULL) {
+                       return; // addrsan should catch malloc-unknown and print more info than we have
+               }
+       }
+}
+
 void* __wrap_malloc(size_t len) {
        void* res = __real_malloc(len);
        new_allocation(res, "malloc call");