Answer the question
In order to leave comments, you need to log in
How to cheat the checking script?
1. There is a script
$val = $_POST['val'];
$balance = 0;
function test($val, $balance){
if(!preg_match("/^\d+(\.\d+)?$/i",$val) || $val<=0){
return false;
}
if($val>$balance){
return false;
}
return true;
}
var_dump(test($val, $balance));
Answer the question
In order to leave comments, you need to log in
|| $val<=0
There is a comparison without data typing. That is, "FFF" will also pass the test.
if(!is_numeric($val) OR (is_numeric($val) AND --condition--))
return false;
else return true;
we will assume that the locale does not change and the fractional delimiter is always a dot.
the regular expression will cut off all lines, except those containing a positive decimal fraction with a separator "." and strings of solid zeros. such strings will be converted into numbers without any consequences for subsequent comparisons with integer zeros, here too a miracle will not happen.
the only way is to exceed float precision in the string
I think that the problem here is in the race condition. For example, on the balance of 1000r. The user launches two requests to withdraw these 1000 rubles at the same time, both scripts are checked at about the same time for the availability of funds on the balance sheet and then calmly write off 1000 rubles to themselves. two times (or three, if you're lucky)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question