Skip to content

Commit 242b23b

Browse files
committed
ext/filter: encode 0xFF in FILTER_SANITIZE_ENCODED
php_filter_encode_url() initialized its 256-byte "must encode" table with memset(tmp, 1, sizeof(tmp) - 1), leaving tmp[255] uninitialized. Whether 0xFF got percent-encoded then depended on stack garbage; valgrind reports the read as a conditional jump on an uninitialised value. Initialize the whole table.
1 parent 5fd38ba commit 242b23b

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

ext/filter/sanitizing_filters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const
6868
unsigned char *e = s + char_len;
6969
zend_string *str;
7070

71-
memset(tmp, 1, sizeof(tmp)-1);
71+
memset(tmp, 1, sizeof(tmp));
7272

7373
while (s < e) {
7474
tmp[*s++] = '\0';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
FILTER_SANITIZE_ENCODED percent-encodes 0xFF
3+
--EXTENSIONS--
4+
filter
5+
--FILE--
6+
<?php
7+
var_dump(filter_var("\xFF", FILTER_SANITIZE_ENCODED));
8+
var_dump(filter_var("\xFE\xFF\x00A", FILTER_SANITIZE_ENCODED));
9+
?>
10+
--EXPECT--
11+
string(3) "%FF"
12+
string(10) "%FE%FF%00A"

0 commit comments

Comments
 (0)