Skip to content

Commit 4b94449

Browse files
niconoe-williamdes
authored andcommitted
Fix #270 - Replace sscanf by equivalent native PHP functions because sscanf can be disabled for security reasons.
Fixes: #270
1 parent f4d0d83 commit 4b94449

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/Token.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,16 @@ public function extract()
252252
if ($this->flags & self::FLAG_NUMBER_HEX) {
253253
if ($this->flags & self::FLAG_NUMBER_NEGATIVE) {
254254
$ret = str_replace('-', '', $this->token);
255-
sscanf($ret, '%x', $ret);
256-
$ret = -$ret;
255+
$ret = -hexdec($ret);
257256
} else {
258-
sscanf($ret, '%x', $ret);
257+
$ret = hexdec($ret);
259258
}
260259
} elseif (($this->flags & self::FLAG_NUMBER_APPROXIMATE)
261260
|| ($this->flags & self::FLAG_NUMBER_FLOAT)
262261
) {
263-
sscanf($ret, '%f', $ret);
264-
} else {
265-
sscanf($ret, '%d', $ret);
262+
$ret = (float) $ret;
263+
} elseif (! ($this->flags & self::FLAG_NUMBER_BINARY)) {
264+
$ret = (int) $ret;
266265
}
267266

268267
return $ret;

tests/data/lexer/lexNumber.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, 0XFfA, 1e-10, 1e10, .5e10, b'10';
1+
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, 0XFfA, -0xFFa, -0xfFA, -0XFfA, 1e-10, 1e10, .5e10, b'10';
22
-- invalid number
33
SELECT 12ex10, b'15';

0 commit comments

Comments
 (0)