DEV Community

Discussion on: Can you find the bug in this piece of php code? ๐Ÿคน

Collapse
 
agounane profile image
agounane

if($params['pin'] === $user->getPin()) {
return "The pin is correct!";
}
throw new HttpException(403, "The pin is incorrect");
// this one is more safer

Collapse
 
posandu profile image
Posandu

Huh?

Collapse
 
williamstam profile image
William Stam

Always check for what you want and not for what you don't. Like in the above its if the passed pin is type and equal to the pin the you have a valid pin.

I remember a thing a while ago where there was (is?) A logic bug in the unreal engine where they basically do something like if the distance you traveled is out of the max then you did something wrong reset else update character position. So anything that triggers the else on that logic block would be "acceptable". Dont do this. Always test for what you want and ease of on the else's. In unreals case the bug was exploited by triggering a null value which if anything null almost always ends in the else block. So the next update on position will be like if last (null) minus now position is out of bounds throw error else update character position. And we know null kicks it to the else so all the positions were basically "ok".

Thread Thread
 
nombrekeff profile image
Keff

Wow, interesting bug, thanks for sharing the story