Skip to content

Commit dd1e775

Browse files
committed
Fix invalid characters passed to hexdec function
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 3a02ade commit dd1e775

File tree

7 files changed

+251
-41
lines changed

7 files changed

+251
-41
lines changed

src/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ public function extract()
254254
case self::TYPE_NUMBER:
255255
$ret = str_replace('--', '', $this->token); // e.g. ---42 === -42
256256
if ($this->flags & self::FLAG_NUMBER_HEX) {
257+
$ret = str_replace(['-', '+'], '', $this->token);
257258
if ($this->flags & self::FLAG_NUMBER_NEGATIVE) {
258-
$ret = str_replace('-', '', $this->token);
259259
$ret = -hexdec($ret);
260260
} else {
261261
$ret = hexdec($ret);

tests/data/bugs/fuzz5.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
+0xO

tests/data/bugs/fuzz5.out

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"query": "+0xO",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "+0xO",
6+
"len": 4,
7+
"last": 4,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "+0x",
14+
"value": 0,
15+
"keyword": null,
16+
"type": 6,
17+
"flags": 1,
18+
"position": 0
19+
},
20+
{
21+
"@type": "PhpMyAdmin\\SqlParser\\Token",
22+
"token": "O",
23+
"value": "O",
24+
"keyword": null,
25+
"type": 0,
26+
"flags": 0,
27+
"position": 3
28+
},
29+
{
30+
"@type": "PhpMyAdmin\\SqlParser\\Token",
31+
"token": null,
32+
"value": null,
33+
"keyword": null,
34+
"type": 9,
35+
"flags": 0,
36+
"position": null
37+
}
38+
],
39+
"count": 3,
40+
"idx": 3
41+
},
42+
"delimiter": ";",
43+
"delimiterLen": 1,
44+
"strict": false,
45+
"errors": []
46+
},
47+
"parser": {
48+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
49+
"list": {
50+
"@type": "@1"
51+
},
52+
"statements": [],
53+
"brackets": 0,
54+
"strict": false,
55+
"errors": []
56+
},
57+
"errors": {
58+
"lexer": [],
59+
"parser": [
60+
[
61+
"Unexpected beginning of statement.",
62+
{
63+
"@type": "@2"
64+
},
65+
0
66+
],
67+
[
68+
"Unexpected beginning of statement.",
69+
{
70+
"@type": "@3"
71+
},
72+
0
73+
]
74+
]
75+
}
76+
}

tests/data/bugs/fuzz6.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-+0x!

tests/data/bugs/fuzz6.out

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"query": "-+0x!",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "-+0x!",
6+
"len": 5,
7+
"last": 5,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "-+0x",
14+
"value": 0,
15+
"keyword": null,
16+
"type": 6,
17+
"flags": 9,
18+
"position": 0
19+
},
20+
{
21+
"@type": "PhpMyAdmin\\SqlParser\\Token",
22+
"token": "!",
23+
"value": "!",
24+
"keyword": null,
25+
"type": 2,
26+
"flags": 2,
27+
"position": 4
28+
},
29+
{
30+
"@type": "PhpMyAdmin\\SqlParser\\Token",
31+
"token": null,
32+
"value": null,
33+
"keyword": null,
34+
"type": 9,
35+
"flags": 0,
36+
"position": null
37+
}
38+
],
39+
"count": 3,
40+
"idx": 3
41+
},
42+
"delimiter": ";",
43+
"delimiterLen": 1,
44+
"strict": false,
45+
"errors": []
46+
},
47+
"parser": {
48+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
49+
"list": {
50+
"@type": "@1"
51+
},
52+
"statements": [],
53+
"brackets": 0,
54+
"strict": false,
55+
"errors": []
56+
},
57+
"errors": {
58+
"lexer": [],
59+
"parser": [
60+
[
61+
"Unexpected beginning of statement.",
62+
{
63+
"@type": "@2"
64+
},
65+
0
66+
]
67+
]
68+
}
69+
}

tests/data/lexer/lexNumber.in

Lines changed: 2 additions & 2 deletions
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, -0xfFA, 1e-10, 1e10, .5e10, b'10';
1+
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, +0xfFA, -0xFFa, -0xfFA, 1e-10, 1e10, .5e10, b'10';
22
-- invalid numbers
3-
SELECT 12ex10, b'15', 0XFfA, -0XFfA;
3+
SELECT 12ex10, b'15', 0XFfA, -0XFfA, +0XFfA;

0 commit comments

Comments
 (0)