3 ms·
In such cases you can insert a barrier with a magic value to detect any array overflow. The other thing to do is to enforce checks on array indices.
by ElBarto 8y ago
In such cases you can insert a barrier with a magic value to detect any array overflow.
The other thing to do is to enforce checks on array indices.
- nneonneo 8y agoYou're referring to canaries, which are special values used to detect if overflows occur. Canaries are usually checked on heap deallocation (resp. stack canaries are checked on stack frame deallocation, i.e. function return). Checking them at any other time is expensive and incurs high overhead. They also don't catch all overflows - an overflow with an attacker-controlled index could easily skip the canary and overwrite whatever lies past it. The problem of memory bounds checking is solvable if you decide to forego memory, processing time, and/or compatibility with existing code. Trying to achieve memory safety while maintaining those three properties is very hard.
- ElBarto 8y agoThere's no way around it. What I described is what higher-level languages do if they provide this sort of protection and it's what must do done if such protection is required.