4 ms·
https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/ https://devblogs.microsoft.com/cppblog/addresssanitizer-asan...
by murderfs 6y ago
https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/ https://devblogs.microsoft.com/cppblog/addresssanitizer-asan...
- quelsolaar 6y agoI would like to be able to query it. Windows used to support IsBadReadPtr and IsBadWritePtr but they have been deprecated. I'm not aware of something similar on Linux.
- tinus_hn 6y agoIt’s not very useful, if a pointer is bad and you access it you’ll crash anyway. The problem is when the pointer is manipulated to be good, but not pointing at what you expect.
- quelsolaar 6y agoLet me give you an example: Lets say you have an API that implements a function similar to memcpy. It interacts with more then one user provided pointer. Lets also assume that the API is something big and complicated like a graphics driver, possibly closed source. If you give it a broken pointer it may crash, but it wont tell you what pointer was bad and in what way. Maybe no pointer was bad, maybe the implementation is broken, or some other param is broken. An API can check other params to make sure they are valid, and many APIs do, bu its not yet possible to check poiners. You have to dig in to the implementation to do that and that's a lot of work even if its opensource. Crashing in your code is great, because the debugger will tell you what is going on, but crashing in someone elses code is much harder to debug. Worse, the code may not crash at all, it may over write another allocation by the same process. The implementation cant check the mallocs, it only crashes if the pointer steps outside of a memory block owned by the process.
- tinus_hn 6y agoWhy would an api be able to tell you anything the debugger can’t? If you want to do what you describe you have to make such changes that the language really isn’t c anymore.
- quelsolaar 6y ago> Why would an api be able to tell you anything the debugger can’t? An error message is much easier to read then a stacktrace, especially if you dont have source-code. > If you want to do what you describe you have to make such changes that the language really isn’t c anymore. I dont want any changes to C. I just want to be able to query a process allocations. the OS has to keep the information in order to implement realloc and free, so the information is already there.
- tinus_hn 6y agoThe operating system doesn’t handle malloc, realloc and free. That task is handled by the C library. All the operating system provides is a way for these functions to claim and release large areas of memory. Applications use malloc to allocate some memory they then use to store a collection of data. Pointers often don’t point to the exact start of that memory area, which is what you need to do memory management. So from a pointer you can’t necessarily realloc or free. And the problem is, if a buffer overruns for instance, you end up writing memory that is allocated and valid, just not for the thing the developer thought. Alternative implementations of malloc exist that try to help with this, by encasing memory between guard pages. Also, with for example glibc malloc you can use the MALLOC_TRACE environment variable to get a log of all allocations.
- quelsolaar 6y agoI already have an alternative implementation of malloc that does this. But i still need Microsoft s help to get the same information from a process that didn't use my implementation. I dont need to free or realloc pointers i just need to know if a pointer is valid.
- tinus_hn 6y agoIn normal processes you can find this through the _heapwalk function: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/heapwalk?view=msvc-160 https://docs.microsoft.com/en-us/cpp/c-runtime-library/refer...