Hacker News new | ask | show | jobs
by nbsd4lyfe 3058 days ago
asserts are for diagnostic-enabled code, don't use them for security checks.
2 comments

This is one area where Rust also differs from C; assert!s are left on in release mode; you use debug_assert! if you want something only in development.
I agree, it's a hella questionable language choice, and not limited to C.

I found out about it through https://github.com/rohe/pysaml2/issues/451

I would argue the opposite, assert() statements are the best way to write defensive and secure C. There might have been a time when people commonly compiled out assert() statements from binaries, but that is only OK if the software was designed for that. Otherwise, that would be like me saying I am going to compile out all strlen() statements from a given binary and then expect it to behave the same.
Secure code should be correct and robust. To assure correctness assert()'s should be used, to assure robustness you should check return values and buffer sizes.