diff --git a/NEWS b/NEWS index ae0f6f3e8ff5..1f084e98cb3f 100644 --- a/NEWS +++ b/NEWS @@ -139,6 +139,8 @@ PHP NEWS . Fixed bug GH-20370 (User stream filters could violate typed property constraints). (alexandre-daubois) . Allowed filtered streams to be casted as fd for select. (Jakub Zelenka) + . Fixed bug GH-21221 (Prevent closing of innerstream of php://temp stream). + (ilutov) - Zip: . Fixed ZipArchive callback being called after executor has shut down. diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 89333d89af9d..211a5d14e6c3 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3045,6 +3045,7 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend internal_function->prop_info = NULL; internal_function->attributes = NULL; internal_function->frameless_function_infos = ptr->frameless_function_infos; + internal_function->fn_flags2 = 0; if (EG(active)) { // at run-time: this ought to only happen if registered with dl() or somehow temporarily at runtime ZEND_MAP_PTR_INIT(internal_function->run_time_cache, zend_arena_calloc(&CG(arena), 1, zend_internal_run_time_cache_reserved_size())); } else { diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 6c850a27cf0f..7d4f3d20cff1 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -4344,7 +4344,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * zend_hash_internal_pointer_reset(function->responseParameters); param = zend_hash_get_current_data_ptr(function->responseParameters); if (param->encode && param->encode->details.type_str) { - smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str)); + smart_str_appends(buf, param->encode->details.type_str); smart_str_appendc(buf, ' '); } else { smart_str_appendl(buf, "UNKNOWN ", 8); @@ -4357,12 +4357,12 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, ", ", 2); } if (param->encode && param->encode->details.type_str) { - smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str)); + smart_str_appends(buf, param->encode->details.type_str); } else { smart_str_appendl(buf, "UNKNOWN", 7); } smart_str_appendl(buf, " $", 2); - smart_str_appendl(buf, param->paramName, strlen(param->paramName)); + smart_str_appends(buf, param->paramName); i++; } ZEND_HASH_FOREACH_END(); smart_str_appendl(buf, ") ", 2); @@ -4371,7 +4371,7 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, "void ", 5); } - smart_str_appendl(buf, function->functionName, strlen(function->functionName)); + smart_str_appends(buf, function->functionName); smart_str_appendc(buf, '('); if (function->requestParameters) { @@ -4381,12 +4381,12 @@ static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ * smart_str_appendl(buf, ", ", 2); } if (param->encode && param->encode->details.type_str) { - smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str)); + smart_str_appends(buf, param->encode->details.type_str); } else { smart_str_appendl(buf, "UNKNOWN", 7); } smart_str_appendl(buf, " $", 2); - smart_str_appendl(buf, param->paramName, strlen(param->paramName)); + smart_str_appends(buf, param->paramName); i++; } ZEND_HASH_FOREACH_END(); } @@ -4442,12 +4442,12 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ switch (type->kind) { case XSD_TYPEKIND_SIMPLE: if (type->encode) { - smart_str_appendl(buf, type->encode->details.type_str, strlen(type->encode->details.type_str)); + smart_str_appends(buf, type->encode->details.type_str); smart_str_appendc(buf, ' '); } else { smart_str_appendl(buf, "anyType ", sizeof("anyType ")-1); } - smart_str_appendl(buf, type->name, strlen(type->name)); + smart_str_appends(buf, type->name); if (type->restrictions && type->restrictions->enumeration) { zend_string *key; @@ -4467,20 +4467,20 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ break; case XSD_TYPEKIND_LIST: smart_str_appendl(buf, "list ", 5); - smart_str_appendl(buf, type->name, strlen(type->name)); + smart_str_appends(buf, type->name); if (type->elements) { sdlTypePtr item_type; smart_str_appendl(buf, " {", 2); ZEND_HASH_FOREACH_PTR(type->elements, item_type) { - smart_str_appendl(buf, item_type->name, strlen(item_type->name)); + smart_str_appends(buf, item_type->name); } ZEND_HASH_FOREACH_END(); smart_str_appendc(buf, '}'); } break; case XSD_TYPEKIND_UNION: smart_str_appendl(buf, "union ", 6); - smart_str_appendl(buf, type->name, strlen(type->name)); + smart_str_appends(buf, type->name); if (type->elements) { sdlTypePtr item_type; int first = 0; @@ -4491,7 +4491,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ smart_str_appendc(buf, ','); first = 0; } - smart_str_appendl(buf, item_type->name, strlen(item_type->name)); + smart_str_appends(buf, item_type->name); } ZEND_HASH_FOREACH_END(); smart_str_appendc(buf, '}'); } @@ -4523,7 +4523,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ smart_str_appendl(buf, ext->val, len); } smart_str_appendc(buf, ' '); - smart_str_appendl(buf, type->name, strlen(type->name)); + smart_str_appends(buf, type->name); if (end != NULL) { smart_str_appends(buf, end); } @@ -4546,7 +4546,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ } else { smart_str_appendl(buf, "anyType ", 8); } - smart_str_appendl(buf, type->name, strlen(type->name)); + smart_str_appends(buf, type->name); if (type->attributes && (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize", sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize")-1)) != NULL && @@ -4561,7 +4561,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ } } else { smart_str_appendl(buf, "struct ", 7); - smart_str_appendl(buf, type->name, strlen(type->name)); + smart_str_appends(buf, type->name); smart_str_appendc(buf, ' '); smart_str_appendl(buf, "{\n", 2); if ((type->kind == XSD_TYPEKIND_RESTRICTION || @@ -4579,7 +4579,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */ smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s)); } smart_str_appendc(buf, ' '); - smart_str_appendl(buf, type->encode->details.type_str, strlen(type->encode->details.type_str)); + smart_str_appends(buf, type->encode->details.type_str); smart_str_appendl(buf, " _;\n", 4); } } diff --git a/ext/standard/tests/gh21221.phpt b/ext/standard/tests/gh21221.phpt new file mode 100644 index 000000000000..8435b4803470 --- /dev/null +++ b/ext/standard/tests/gh21221.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-21221: Prevent closing of innerstream of php://temp stream +--CREDITS-- +chongwick +--FILE-- + +--EXPECTF-- +Warning: fclose(): cannot close the provided stream, as it must not be manually closed in %s on line %d diff --git a/main/streams/streams.c b/main/streams/streams.c index 85d2947c28a6..32c7ba99f58c 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -105,6 +105,7 @@ PHPAPI php_stream *php_stream_encloses(php_stream *enclosing, php_stream *enclos php_stream *orig = enclosed->enclosing_stream; php_stream_auto_cleanup(enclosed); + enclosed->flags |= PHP_STREAM_FLAG_NO_FCLOSE; enclosed->enclosing_stream = enclosing; return orig; }