com php-src: Fix #78114: segfault when calling sodium_* fun ctions from eval: NEWS ext/sodium/libsodium.c ext /sodium/tests/bug78114.phpt
| From: | Christoph Michael Becker | Date: | Thu, 06 Jun 2019 08:00:15 +0000 |
| Subject: | com php-src: Fix #78114: segfault when calling sodium_* fun ctions from eval: NEWS ext/sodium/libsodium.c ext /sodium/tests/bug78114.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106584@lists.php.net to get a copy of this message | ||
Commit: 22a3fa0b2e31e33665765bde630bc6c6f0dd475b
Author: Christoph M. Becker <cmbecker69@gmx.de> Thu, 6 Jun 2019 09:29:44 +0200
Parents: 249c20023d4446d81a2904dc5e8d3aa4a3a2d016
Branches: PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=22a3fa0b2e31e33665765bde630bc6c6f0dd475b
Log:
Fix #78114: segfault when calling sodium_* functions from eval
We must not follow the NULL pointer.
Bugs:
https://bugs.php.net/78114
Changed paths:
M NEWS
M ext/sodium/libsodium.c
A ext/sodium/tests/bug78114..phpt
Diff:
diff --git a/NEWS b/NEWS
index 65a2d67..107b73f 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,9 @@ PHP NEWS
. Fixed bug #78038 (Socket_select fails when resource array contains
references). (Nikita)
+- Sodium:
+ . Fixed bug #78114 (segfault when calling sodium_* functions from eval). (cmb)
+
- Zip:
. Fixed bug #76345 (zip.h not found). (Michael Maroszek)
diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c
index 50a9119..1ee09e0 100644
--- a/ext/sodium/libsodium.c
+++ b/ext/sodium/libsodium.c
@@ -387,8 +387,10 @@ static void sodium_remove_param_values_from_backtrace(zend_object *obj) {
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) {
if (Z_TYPE_P(frame) == IS_ARRAY) {
zval *args = zend_hash_str_find(Z_ARRVAL_P(frame), "args",
sizeof("args")-1);
- zval_ptr_dtor(args);
- ZVAL_EMPTY_ARRAY(args);
+ if (args) {
+ zval_ptr_dtor(args);
+ ZVAL_EMPTY_ARRAY(args);
+ }
}
} ZEND_HASH_FOREACH_END();
}
diff --git a/ext/sodium/tests/bug78114.phpt b/ext/sodium/tests/bug78114.phpt
new file mode 100644
index 0000000..c697ea1
--- /dev/null
+++ b/ext/sodium/tests/bug78114.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug #78114 (segfault when calling sodium_* functions from eval)
+--SKIPIF--
+<?php
+if (!extension_loaded('sodium')) die('skip sodium extension not available');
+?>
+--FILE--
+<?php
+try {
+ eval('sodium_bin2hex();');
+} catch (Throwable $ex) {
+ echo $ex->getMessage(), PHP_EOL;
+}
+?>
+--EXPECT--
+sodium_bin2hex() expects exactly 1 parameter, 0 given