summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Fuhrmannek2021-12-13 13:57:18 +0100
committerBen Fuhrmannek2021-12-13 13:57:18 +0100
commit682cf7e9b05833cb7502f29edbcf4e0fa567cdf4 (patch)
treeb55df914267cc002e62dbf680bf8f3c2706823f2
parent08725a0b7fce751c333e0dba2f6df6838dea15de (diff)
fixed use after free + PHP 7 compatibility
-rw-r--r--src/sp_unserialize.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/sp_unserialize.c b/src/sp_unserialize.c
index 4a9f565..c2173d3 100644
--- a/src/sp_unserialize.c
+++ b/src/sp_unserialize.c
@@ -1,14 +1,25 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3// condensed version of PHP's php_hash_do_hash_hmac() in ext/hash/hash.c 3// condensed version of PHP's php_hash_do_hash_hmac() in ext/hash/hash.c
4#if PHP_VERSION_ID < 80000
5static inline void *php_hash_alloc_context(const php_hash_ops *ops) {
6 /* Zero out context memory so serialization doesn't expose internals */
7 return ecalloc(1, ops->context_size);
8}
9#endif
10
4static zend_string *sp_do_hash_hmac_sha256(char *data, size_t data_len, char *key, size_t key_len) 11static zend_string *sp_do_hash_hmac_sha256(char *data, size_t data_len, char *key, size_t key_len)
5{ 12{
13#if PHP_VERSION_ID < 80000
14 const php_hash_ops *ops = php_hash_fetch_ops(ZEND_STRL("sha256"));
15#else
6 zend_string *algo = zend_string_init(ZEND_STRL("sha256"), 0); 16 zend_string *algo = zend_string_init(ZEND_STRL("sha256"), 0);
7 const php_hash_ops *ops = php_hash_fetch_ops(algo); 17 const php_hash_ops *ops = php_hash_fetch_ops(algo);
8 zend_string_release_ex(algo, 0); 18 zend_string_release_ex(algo, 0);
19#endif
9 20
10 if (!ops || !ops->is_crypto) { 21 if (!ops || !ops->is_crypto) {
11 sp_log_err("unsupported hash algorithm for hmac: %s", ZSTR_VAL(algo)); 22 sp_log_err("hmac", "unsupported hash algorithm: sha256");
12 return NULL; 23 return NULL;
13 } 24 }
14 25
@@ -35,6 +46,8 @@ static zend_string *sp_do_hash_hmac_sha256(char *data, size_t data_len, char *ke
35 return hex_digest; 46 return hex_digest;
36} 47}
37 48
49// ------------------
50
38PHP_FUNCTION(sp_serialize) { 51PHP_FUNCTION(sp_serialize) {
39 zif_handler orig_handler; 52 zif_handler orig_handler;
40 53