diff options
Diffstat (limited to 'src/sp_disable_xxe.c')
| -rw-r--r-- | src/sp_disable_xxe.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/sp_disable_xxe.c b/src/sp_disable_xxe.c index 3ef1a5d..9dea33c 100644 --- a/src/sp_disable_xxe.c +++ b/src/sp_disable_xxe.c | |||
| @@ -1,6 +1,14 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | PHP_FUNCTION(sp_libxml_disable_entity_loader) { RETURN_TRUE; } | 3 | PHP_FUNCTION(sp_libxml_disable_entity_loader) { |
| 4 | sp_log_warn( "xxe", "A call to libxml_disable_entity_loader was tried and nopped"); | ||
| 5 | RETURN_TRUE; | ||
| 6 | } | ||
| 7 | |||
| 8 | PHP_FUNCTION(sp_libxml_set_external_entity_loader) { | ||
| 9 | sp_log_warn("xxe", "A call to libxml_set_external_entity_loader was tried and nopped"); | ||
| 10 | RETURN_TRUE; | ||
| 11 | } | ||
| 4 | 12 | ||
| 5 | int hook_libxml_disable_entity_loader() { | 13 | int hook_libxml_disable_entity_loader() { |
| 6 | TSRMLS_FETCH(); | 14 | TSRMLS_FETCH(); |
| @@ -10,19 +18,21 @@ int hook_libxml_disable_entity_loader() { | |||
| 10 | zval params[1]; | 18 | zval params[1]; |
| 11 | 19 | ||
| 12 | #if PHP_VERSION_ID < 80000 | 20 | #if PHP_VERSION_ID < 80000 |
| 13 | // This function is deprecated in PHP8, but better safe than sorry for php7. | 21 | // This function is deprecated in PHP8, but better safe than sorry for php7. |
| 14 | ZVAL_STRING(&func_name, "libxml_disable_entity_loader"); | 22 | ZVAL_STRING(&func_name, "libxml_disable_entity_loader"); |
| 15 | ZVAL_STRING(¶ms[0], "true"); | 23 | ZVAL_STRING(¶ms[0], "true"); |
| 16 | call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params); | 24 | call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params); |
| 17 | #endif | 25 | #endif |
| 18 | 26 | ||
| 19 | // This is now the recommended way to disable external entities | 27 | // This is now the recommended way to disable external entities |
| 20 | ZVAL_STRING(&func_name, "libxml_set_external_entity_loader"); | 28 | ZVAL_STRING(&func_name, "libxml_set_external_entity_loader"); |
| 21 | ZVAL_NULL(¶ms[0]); | 29 | ZVAL_NULL(¶ms[0]); |
| 22 | call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params); | 30 | call_user_function(CG(function_table), NULL, &func_name, &retval, 1, params); |
| 23 | 31 | ||
| 24 | HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook, | 32 | HOOK_FUNCTION("libxml_disable_entity_loader", sp_internal_functions_hook, |
| 25 | PHP_FN(sp_libxml_disable_entity_loader)); | 33 | PHP_FN(sp_libxml_disable_entity_loader)); |
| 34 | HOOK_FUNCTION("libxml_set_external_entity_loader", sp_internal_functions_hook, | ||
| 35 | PHP_FN(sp_libxml_set_external_entity_loader)); | ||
| 26 | 36 | ||
| 27 | return SUCCESS; | 37 | return SUCCESS; |
| 28 | } | 38 | } |
