|
|
|
|
|
by nayuki
2250 days ago
|
|
The article says: "may crash due to a NULL pointer dereference". But in C, dereferencing a null pointer is undefined behavior. Crashing is only one possible outcome, and arguably the best outcome. The compiler and optimizer is entitled to elide certain checks or simplify code under the assumption that a pointer being dereferenced should not be null, and this could lead to dangerous things. Here's an artificial example: int x = 0;
int *p;
if (...some condition...)
p = &x;
else
p = NULL;
print(*p);
The compiler is allowed to simplify the code to: int x = 0;
int *p;
p = &x;
print(*p);
It's because the 'else' branch must cause a null pointer dereference, so that case can be legally ignored. |
|
Here's the bug: https://svnweb.freebsd.org/base/releng/12.1/crypto/openssl/s...
Value NULL is generally (void *)0 (could be different on different architectures, but it supposed to point to invalid value in memory, so when that memory address is accessed it will trigger segmentation fault.