|
74 | 74 | } \ |
75 | 75 | obj = Z_TIDY_P(object); \ |
76 | 76 |
|
77 | | -#define TIDY_APPLY_CONFIG(_doc, _val_str, _val_ht) \ |
78 | | - if (_val_ht) { \ |
79 | | - _php_tidy_apply_config_array(_doc, _val_ht); \ |
80 | | - } else if (_val_str) { \ |
81 | | - TIDY_OPEN_BASE_DIR_CHECK(ZSTR_VAL(_val_str)); \ |
82 | | - php_tidy_load_config(_doc, ZSTR_VAL(_val_str)); \ |
83 | | - } |
84 | | - |
85 | | -#define TIDY_OPEN_BASE_DIR_CHECK(filename) \ |
86 | | -if (php_check_open_basedir(filename)) { \ |
87 | | - RETURN_FALSE; \ |
88 | | -} \ |
89 | | - |
90 | 77 | #define TIDY_SET_DEFAULT_CONFIG(_doc) \ |
91 | 78 | if (TG(default_config) && TG(default_config)[0]) { \ |
92 | 79 | php_tidy_load_config(_doc, TG(default_config)); \ |
@@ -221,6 +208,19 @@ static void php_tidy_load_config(TidyDoc doc, const char *path) |
221 | 208 | } |
222 | 209 | } |
223 | 210 |
|
| 211 | +static zend_result php_tidy_apply_config(TidyDoc doc, zend_string *str_string, HashTable *ht_options) |
| 212 | +{ |
| 213 | + if (ht_options) { |
| 214 | + return _php_tidy_apply_config_array(doc, ht_options); |
| 215 | + } else if (str_string) { |
| 216 | + if (php_check_open_basedir(ZSTR_VAL(str_string))) { |
| 217 | + return FAILURE; |
| 218 | + } |
| 219 | + php_tidy_load_config(doc, ZSTR_VAL(str_string)); |
| 220 | + } |
| 221 | + return SUCCESS; |
| 222 | +} |
| 223 | + |
224 | 224 | static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value) |
225 | 225 | { |
226 | 226 | TidyOption opt = tidyGetOptionByName(doc, optname); |
@@ -329,9 +329,9 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, bool is_file) |
329 | 329 |
|
330 | 330 | TIDY_SET_DEFAULT_CONFIG(doc); |
331 | 331 |
|
332 | | - TIDY_APPLY_CONFIG(doc, config_str, config_ht); |
333 | | - |
334 | | - if(enc_len) { |
| 332 | + if (php_tidy_apply_config(doc, config_str, config_ht) != SUCCESS) { |
| 333 | + RETVAL_FALSE; |
| 334 | + } else if (enc_len) { |
335 | 335 | if (tidySetCharEncoding(doc, enc) < 0) { |
336 | 336 | php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc); |
337 | 337 | RETVAL_FALSE; |
@@ -1024,9 +1024,8 @@ PHP_FUNCTION(tidy_parse_string) |
1024 | 1024 | tidy_instantiate(tidy_ce_doc, return_value); |
1025 | 1025 | obj = Z_TIDY_P(return_value); |
1026 | 1026 |
|
1027 | | - TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); |
1028 | | - |
1029 | | - if (php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == FAILURE) { |
| 1027 | + if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht) != SUCCESS |
| 1028 | + || php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == FAILURE) { |
1030 | 1029 | zval_ptr_dtor(return_value); |
1031 | 1030 | RETURN_FALSE; |
1032 | 1031 | } |
@@ -1093,9 +1092,8 @@ PHP_FUNCTION(tidy_parse_file) |
1093 | 1092 | tidy_instantiate(tidy_ce_doc, return_value); |
1094 | 1093 | obj = Z_TIDY_P(return_value); |
1095 | 1094 |
|
1096 | | - TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); |
1097 | | - |
1098 | | - if (php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == FAILURE) { |
| 1095 | + if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht) != SUCCESS |
| 1096 | + || php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == FAILURE) { |
1099 | 1097 | zval_ptr_dtor(return_value); |
1100 | 1098 | RETVAL_FALSE; |
1101 | 1099 | } |
@@ -1388,7 +1386,11 @@ PHP_METHOD(tidy, __construct) |
1388 | 1386 | RETURN_THROWS(); |
1389 | 1387 | } |
1390 | 1388 |
|
1391 | | - TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); |
| 1389 | + if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht) != SUCCESS) { |
| 1390 | + /* TODO: this is the constructor, we should throw probably... */ |
| 1391 | + zend_string_release_ex(contents, 0); |
| 1392 | + RETURN_FALSE; |
| 1393 | + } |
1392 | 1394 |
|
1393 | 1395 | php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc); |
1394 | 1396 |
|
@@ -1427,9 +1429,8 @@ PHP_METHOD(tidy, parseFile) |
1427 | 1429 | RETURN_THROWS(); |
1428 | 1430 | } |
1429 | 1431 |
|
1430 | | - TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); |
1431 | | - |
1432 | | - if (php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == FAILURE) { |
| 1432 | + if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht) != SUCCESS |
| 1433 | + || php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == FAILURE) { |
1433 | 1434 | RETVAL_FALSE; |
1434 | 1435 | } else { |
1435 | 1436 | RETVAL_TRUE; |
@@ -1461,9 +1462,8 @@ PHP_METHOD(tidy, parseString) |
1461 | 1462 | TIDY_SET_CONTEXT; |
1462 | 1463 | obj = Z_TIDY_P(object); |
1463 | 1464 |
|
1464 | | - TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); |
1465 | | - |
1466 | | - if(php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == SUCCESS) { |
| 1465 | + if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht) == SUCCESS |
| 1466 | + && php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == SUCCESS) { |
1467 | 1467 | RETURN_TRUE; |
1468 | 1468 | } |
1469 | 1469 |
|
|
0 commit comments