We have already known that use-after-free vulnerabilities could cause the security problems. Since the use-after-free error is born from dangling pointer, my question is that if the dangling pointers are not being used in a program, are they considered safe or benign(not such dangerous)?
A unused dangling pointer is not dangerous...until the next developer uses it.
You tagged the question as C and C++; I'll consider you work with C++, not C.
For C++, avoid raw pointers with obscure semantics, and dangling tendencies. Using unique_ptr
and shared_ptr
can help you a great deal there.
Anyway, avoid dangling pointers. It costs nearly nothing to set a deleted pointer to nullptr
and it can save tons of dev/debug time.
If you face the problem of dangling pointers, or at least the question associated with them, you probably have there an opportunity to apply the beautiful rule of zero
: either your class manages memory (you are writing a container, a specific cool fancy pointer wrapper or the like), or you are writing a non-managing class that should not own any raw pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With