diff options
| author | jvoisin | 2025-10-24 23:49:49 +0200 |
|---|---|---|
| committer | jvoisin | 2025-10-24 23:55:10 +0200 |
| commit | a167c4d23feb03e6c5b53f41724bbfcb813bf04b (patch) | |
| tree | fc18270de1994cce6bd997625dfc22c32f8dcb8c /src/sp_unserialize.c | |
| parent | 040f11d6c2ab54e3990a5887b8cebf7a00d17071 (diff) | |
fix(unserialize): don't bail in simulation mode when there's no HMAC
Diffstat (limited to '')
| -rw-r--r-- | src/sp_unserialize.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/sp_unserialize.c b/src/sp_unserialize.c index 4442997..3e810fc 100644 --- a/src/sp_unserialize.c +++ b/src/sp_unserialize.c | |||
| @@ -110,9 +110,27 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 110 | #endif | 110 | #endif |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | const sp_config_unserialize *config_unserialize = &(SPCFG(unserialize)); | ||
| 114 | #if ! (PHP_VERSION_ID >= 80300) | ||
| 115 | zif_handler orig_handler = zend_hash_str_find_ptr(SPG(sp_internal_functions_hook), ZEND_STRL("unserialize")); | ||
| 116 | #endif | ||
| 117 | |||
| 113 | /* 64 is the length of HMAC-256 */ | 118 | /* 64 is the length of HMAC-256 */ |
| 114 | if (buf_len < 64) { | 119 | if (buf_len < 64) { |
| 115 | sp_log_drop("unserialize", "The serialized object is too small."); | 120 | if (true == config_unserialize->simulation) { |
| 121 | sp_log_simulation("unserialize", "The serialized object is smaller than 64: assuming there is no HMAC"); | ||
| 122 | #if PHP_VERSION_ID >= 80300 | ||
| 123 | // PHP8.3 gives a warning about trailing data in unserialize strings. | ||
| 124 | php_unserialize_with_options(return_value, buf, buf_len, opts, "unserialize"); | ||
| 125 | #else | ||
| 126 | if ((orig_handler)) { | ||
| 127 | orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU); | ||
| 128 | } | ||
| 129 | #endif | ||
| 130 | return; | ||
| 131 | } else { | ||
| 132 | sp_log_drop("unserialize", "The serialized object is too small."); | ||
| 133 | } | ||
| 116 | } | 134 | } |
| 117 | 135 | ||
| 118 | char* hmac = buf + buf_len - 64; | 136 | char* hmac = buf + buf_len - 64; |
| @@ -128,9 +146,6 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 128 | } | 146 | } |
| 129 | } else { status = 1; } | 147 | } else { status = 1; } |
| 130 | 148 | ||
| 131 | #if ! (PHP_VERSION_ID >= 80300) | ||
| 132 | zif_handler orig_handler = zend_hash_str_find_ptr(SPG(sp_internal_functions_hook), ZEND_STRL("unserialize")); | ||
| 133 | #endif | ||
| 134 | if (0 == status) { | 149 | if (0 == status) { |
| 135 | #if PHP_VERSION_ID >= 80300 | 150 | #if PHP_VERSION_ID >= 80300 |
| 136 | // PHP8.3 gives a warning about trailing data in unserialize strings. | 151 | // PHP8.3 gives a warning about trailing data in unserialize strings. |
| @@ -141,7 +156,6 @@ PHP_FUNCTION(sp_unserialize) { | |||
| 141 | } | 156 | } |
| 142 | #endif | 157 | #endif |
| 143 | } else { | 158 | } else { |
| 144 | const sp_config_unserialize *config_unserialize = &(SPCFG(unserialize)); | ||
| 145 | if (config_unserialize->dump) { | 159 | if (config_unserialize->dump) { |
| 146 | sp_log_request(config_unserialize->dump, | 160 | sp_log_request(config_unserialize->dump, |
| 147 | config_unserialize->textual_representation); | 161 | config_unserialize->textual_representation); |
