Skip to content

Commit 6501136

Browse files
committed
add test
1 parent 66d01e3 commit 6501136

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

ext/openssl/tests/gh22186.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-22186 (Heap buffer overflow in openssl_encrypt with AES-WRAP-PAD)
3+
--EXTENSIONS--
4+
openssl
5+
--SKIPIF--
6+
<?php
7+
if (!in_array('aes-128-wrap-pad', openssl_get_cipher_methods(), true)) {
8+
die('skip aes-128-wrap-pad not available');
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
$pass = str_repeat("k", 16);
14+
$iv = str_repeat("\0", 4);
15+
16+
for ($i = 1; $i < 258; $i++) {
17+
$data = str_repeat("a", $i);
18+
$enc = openssl_encrypt($data, 'aes-128-wrap-pad', $pass, OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY, $iv);
19+
$dec = openssl_decrypt($enc, 'aes-128-wrap-pad', $pass, OPENSSL_RAW_DATA | OPENSSL_DONT_ZERO_PAD_KEY, $iv);
20+
if ($dec !== $data) {
21+
die("mismatch at $i\n");
22+
}
23+
}
24+
25+
echo "done\n";
26+
?>
27+
--EXPECT--
28+
done

0 commit comments

Comments
 (0)