-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SIGSEGV in openssl_random_pseudo_bytes and xor_strings (#985)
SIGSEGV was caused by using wrong string's constructor. The constructor we used was an optimization for single-character strings. Such strings are stored in `.rodata`. Writing to these strings' buffer led to a SIGSEGV
- Loading branch information
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@ok | ||
<?php | ||
|
||
function is_kphp() { | ||
#ifndef KPHP | ||
return false; | ||
#endif | ||
return true; | ||
} | ||
|
||
function test_openssl_random_pseudo_bytes() { | ||
for ($i = -300; $i < 2048; $i += 273) { | ||
$res = ""; | ||
|
||
if (is_kphp()) { | ||
$res = openssl_random_pseudo_bytes($i); | ||
if ($res === false && $i < 1) { | ||
print("error"); | ||
} | ||
} else { | ||
try { | ||
$res = openssl_random_pseudo_bytes($i); | ||
} catch (Exception $e) { | ||
if ($i < 1) { | ||
print("error"); | ||
} else { | ||
critical_error("unexpected exception"); | ||
} | ||
} | ||
} | ||
var_dump($res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@ok | ||
<?php | ||
|
||
function is_kphp() { | ||
#ifndef KPHP | ||
return false; | ||
#endif | ||
return true; | ||
} | ||
|
||
function test_xor_strings() { | ||
$strings = ["handling and manipulating", "ings, take a look", "ctory Access Protocol", "0000000dwxasd", "1111sadsd11", "a", "-"]; | ||
|
||
foreach ($strings as $str1) { | ||
foreach($strings as $str2) { | ||
if (is_kphp()) { | ||
$res = xor_strings($str1, $str2); | ||
} else { | ||
$res = $str1 ^ $str2; | ||
} | ||
var_dump($res); | ||
} | ||
} | ||
} |