|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-09-18 18:56 UTC] tonglebeak at gmail dot com
Description: ------------ Normally, whenever and int 0 is put into an if statement, the statement is returned as false. Same thing with double 0: it returns false. However, with a decimal, it's returning true. 0.0000000 is an example that is returning true. This can lead to possible security issues for those who rely on the if statement, and are using it on a decimal taken from a database for example for security checks and such. Reproduce code: --------------- <? $num='0.000000000'; if ($num) echo 'decimal true'; if ((int)$num) echo 'int true'; if ((double)$num) echo 'double true'; ?> Expected result: ---------------- I expect nothing to return true at all. Actual result: -------------- 'decimal true' is returned, meaning "if (0.000000000)" is returning true. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 01:00:01 2025 UTC |
Ok, I'm going to make a big edit here. It is only occurs when it's fetched from a database. I just realized the other way shows it as a string v_v. Here's an example of the security issue: <? //my file to connect to the database is here $row=mysql_fetch_row(mysql_query('SELECT score FROM games WHERE score=0 LIMIT 0,1')); /*Please note: the field for 'score' is a decimal type, and the data being fetched is 0.0000000000*/ if ($row[0]) echo 'true'; ?> And guess what: it echos 'true';