I read the book [rus] (sorry, I can not find the English version at the moment), written by Kris Kaspersky explains the philosophy and methods of software security.
There is one example in the book. It states that the code:
if ( ! IsValidUser() ) { Message("Invalid user! Abroting..."); Abort; }
absolutely unsafe because it translates to this:
CALL IsValidUser OR AX,AX JZ continue ^^^^^^^^^^^^^ PUSH offset str_invalid_user CALL Message CALL Abort continue: ; normal program execution ...........
Thus, the program can be hacked by changing only one byte in the disassembler. If we change JZ continue to JMP continue , the check will fail.
Then Chris writes:
fixed version of the program in C:
IsValidUser(); if (!true) { Message("Invalid user! Aborting..."); Abort; }
In this version, the {...} section will never gain control.
I really don't understand how the fixed version should work. Why does it use an if-statement that will never be executed, maybe even be deleted by the compiler?
Is this a typo or a mistake? Or am I not getting anything?
source share