Skip to content

Remove deprecated iconv INI settings #5491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 26 additions & 133 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "ext/standard/info.h"
#include "main/php_output.h"
#include "SAPI.h"
#include "php_ini.h"

#include <stdlib.h>
#include <errno.h>
Expand Down Expand Up @@ -56,9 +55,6 @@
#define _php_iconv_memequal(a, b, c) \
(memcmp(a, b, c) == 0)

ZEND_DECLARE_MODULE_GLOBALS(iconv)
static PHP_GINIT_FUNCTION(iconv);

/* {{{ iconv_module_entry */
zend_module_entry iconv_module_entry = {
STANDARD_MODULE_HEADER,
Expand All @@ -70,11 +66,7 @@ zend_module_entry iconv_module_entry = {
NULL,
PHP_MINFO(miconv),
PHP_ICONV_VERSION,
PHP_MODULE_GLOBALS(iconv),
PHP_GINIT(iconv),
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
STANDARD_MODULE_PROPERTIES,
};
/* }}} */

Expand All @@ -85,18 +77,6 @@ ZEND_TSRMLS_CACHE_DEFINE()
ZEND_GET_MODULE(iconv)
#endif

/* {{{ PHP_GINIT_FUNCTION */
static PHP_GINIT_FUNCTION(iconv)
{
#if defined(COMPILE_DL_ICONV) && defined(ZTS)
ZEND_TSRMLS_CACHE_UPDATE();
#endif
iconv_globals->input_encoding = NULL;
iconv_globals->output_encoding = NULL;
iconv_globals->internal_encoding = NULL;
}
/* }}} */

#if defined(HAVE_LIBICONV) && defined(ICONV_ALIASED_LIBICONV)
#define iconv libiconv
#endif
Expand Down Expand Up @@ -141,61 +121,11 @@ static const char _generic_superset_name[] = ICONV_UCS4_ENCODING;
#define GENERIC_SUPERSET_NBYTES 4
/* }}} */


static PHP_INI_MH(OnUpdateInputEncoding)
{
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
return FAILURE;
}
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.input_encoding is deprecated");
}
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}


static PHP_INI_MH(OnUpdateOutputEncoding)
{
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
return FAILURE;
}
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.output_encoding is deprecated");
}
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}


static PHP_INI_MH(OnUpdateInternalEncoding)
{
if (ZSTR_LEN(new_value) >= ICONV_CSNMAXLEN) {
return FAILURE;
}
if (stage & (PHP_INI_STAGE_ACTIVATE | PHP_INI_STAGE_RUNTIME)) {
php_error_docref("ref.iconv", E_DEPRECATED, "Use of iconv.internal_encoding is deprecated");
}
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}


/* {{{ PHP_INI */
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("iconv.input_encoding", "", PHP_INI_ALL, OnUpdateInputEncoding, input_encoding, zend_iconv_globals, iconv_globals)
STD_PHP_INI_ENTRY("iconv.output_encoding", "", PHP_INI_ALL, OnUpdateOutputEncoding, output_encoding, zend_iconv_globals, iconv_globals)
STD_PHP_INI_ENTRY("iconv.internal_encoding", "", PHP_INI_ALL, OnUpdateInternalEncoding, internal_encoding, zend_iconv_globals, iconv_globals)
PHP_INI_END()
/* }}} */

/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(miconv)
{
char *version = "unknown";

REGISTER_INI_ENTRIES();

#ifdef HAVE_LIBICONV
{
static char buf[16];
Expand Down Expand Up @@ -234,7 +164,6 @@ PHP_MINIT_FUNCTION(miconv)
PHP_MSHUTDOWN_FUNCTION(miconv)
{
php_iconv_stream_filter_unregister_factory();
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
/* }}} */
Expand All @@ -252,33 +181,9 @@ PHP_MINFO_FUNCTION(miconv)
php_info_print_table_row(2, "iconv implementation", Z_STRVAL_P(iconv_impl));
php_info_print_table_row(2, "iconv library version", Z_STRVAL_P(iconv_ver));
php_info_print_table_end();

DISPLAY_INI_ENTRIES();
}
/* }}} */

static const char *get_internal_encoding(void) {
if (ICONVG(internal_encoding) && ICONVG(internal_encoding)[0]) {
return ICONVG(internal_encoding);
}
return php_get_internal_encoding();
}

static const char *get_input_encoding(void) {
if (ICONVG(input_encoding) && ICONVG(input_encoding)[0]) {
return ICONVG(input_encoding);
}
return php_get_input_encoding();
}

static const char *get_output_encoding(void) {
if (ICONVG(output_encoding) && ICONVG(output_encoding)[0]) {
return ICONVG(output_encoding);
}
return php_get_output_encoding();
}


static int php_iconv_output_conflict(const char *handler_name, size_t handler_name_len)
{
if (php_output_get_level()) {
Expand Down Expand Up @@ -319,12 +224,16 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c

if (mimetype != NULL && !(output_context->op & PHP_OUTPUT_HANDLER_CLEAN)) {
size_t len;
char *p = strstr(get_output_encoding(), "//");
char *p = strstr(php_get_output_encoding(), "//");

if (p) {
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, (int) (p - get_output_encoding()), get_output_encoding());
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%.*s",
mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype,
(int) (p - php_get_output_encoding()), php_get_output_encoding());
} else {
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s", mimetype_len ? mimetype_len : (int) strlen(mimetype), mimetype, get_output_encoding());
len = spprintf(&content_type, 0, "Content-Type:%.*s; charset=%s",
mimetype_len ? mimetype_len : (int) strlen(mimetype),
mimetype, php_get_output_encoding());
}
if (content_type && SUCCESS == sapi_add_header(content_type, len, 0)) {
SG(sapi_headers).send_default_content_type = 0;
Expand All @@ -336,7 +245,9 @@ static int php_iconv_output_handler(void **nothing, php_output_context *output_c
if (output_context->in.used) {
zend_string *out;
output_context->out.free = 1;
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &out, get_output_encoding(), get_internal_encoding()), get_output_encoding(), get_internal_encoding());
_php_iconv_show_error(php_iconv_string(output_context->in.data, output_context->in.used, &out,
php_get_output_encoding(), php_get_internal_encoding()), php_get_output_encoding(),
php_get_internal_encoding());
if (out) {
output_context->out.data = estrndup(ZSTR_VAL(out), ZSTR_LEN(out));
output_context->out.used = ZSTR_LEN(out);
Expand Down Expand Up @@ -1836,7 +1747,7 @@ PHP_FUNCTION(iconv_strlen)
}

if (charset == NULL) {
charset = get_internal_encoding();
charset = php_get_internal_encoding();
} else if (charset_len >= ICONV_CSNMAXLEN) {
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
RETURN_FALSE;
Expand Down Expand Up @@ -1872,7 +1783,7 @@ PHP_FUNCTION(iconv_substr)
}

if (charset == NULL) {
charset = get_internal_encoding();
charset = php_get_internal_encoding();
} else if (charset_len >= ICONV_CSNMAXLEN) {
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
RETURN_FALSE;
Expand Down Expand Up @@ -1913,7 +1824,7 @@ PHP_FUNCTION(iconv_strpos)
}

if (charset == NULL) {
charset = get_internal_encoding();
charset = php_get_internal_encoding();
} else if (charset_len >= ICONV_CSNMAXLEN) {
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
RETURN_FALSE;
Expand Down Expand Up @@ -1972,7 +1883,7 @@ PHP_FUNCTION(iconv_strrpos)
}

if (charset == NULL) {
charset = get_internal_encoding();
charset = php_get_internal_encoding();
} else if (charset_len >= ICONV_CSNMAXLEN) {
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
RETURN_FALSE;
Expand Down Expand Up @@ -2000,7 +1911,7 @@ PHP_FUNCTION(iconv_mime_encode)
smart_str retval = {0};
php_iconv_err_t err;

const char *in_charset = get_internal_encoding();
const char *in_charset = php_get_internal_encoding();
const char *out_charset = in_charset;
zend_long line_len = 76;
const char *lfchars = "\r\n";
Expand Down Expand Up @@ -2111,7 +2022,7 @@ PHP_FUNCTION(iconv_mime_decode)
}

if (charset == NULL) {
charset = get_internal_encoding();
charset = php_get_internal_encoding();
} else if (charset_len >= ICONV_CSNMAXLEN) {
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
RETURN_FALSE;
Expand Down Expand Up @@ -2152,7 +2063,7 @@ PHP_FUNCTION(iconv_mime_decode_headers)
}

if (charset == NULL) {
charset = get_internal_encoding();
charset = php_get_internal_encoding();
} else if (charset_len >= ICONV_CSNMAXLEN) {
php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN);
RETURN_FALSE;
Expand Down Expand Up @@ -2269,8 +2180,7 @@ PHP_FUNCTION(iconv_set_encoding)
{
char *type;
zend_string *charset;
size_t type_len, retval;
zend_string *name;
size_t type_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS", &type, &type_len, &charset) == FAILURE) {
RETURN_THROWS();
Expand All @@ -2281,24 +2191,7 @@ PHP_FUNCTION(iconv_set_encoding)
RETURN_FALSE;
}

if(!strcasecmp("input_encoding", type)) {
name = zend_string_init("iconv.input_encoding", sizeof("iconv.input_encoding") - 1, 0);
} else if(!strcasecmp("output_encoding", type)) {
name = zend_string_init("iconv.output_encoding", sizeof("iconv.output_encoding") - 1, 0);
} else if(!strcasecmp("internal_encoding", type)) {
name = zend_string_init("iconv.internal_encoding", sizeof("iconv.internal_encoding") - 1, 0);
} else {
RETURN_FALSE;
}

retval = zend_alter_ini_entry(name, charset, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
zend_string_release_ex(name, 0);

if (retval == SUCCESS) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
RETURN_FALSE;
}
/* }}} */

Expand All @@ -2314,15 +2207,15 @@ PHP_FUNCTION(iconv_get_encoding)

if (!strcasecmp("all", type)) {
array_init(return_value);
add_assoc_string(return_value, "input_encoding", get_input_encoding());
add_assoc_string(return_value, "output_encoding", get_output_encoding());
add_assoc_string(return_value, "internal_encoding", get_internal_encoding());
add_assoc_string(return_value, "input_encoding", php_get_input_encoding());
add_assoc_string(return_value, "output_encoding", php_get_output_encoding());
add_assoc_string(return_value, "internal_encoding", php_get_internal_encoding());
} else if (!strcasecmp("input_encoding", type)) {
RETVAL_STRING(get_input_encoding());
RETVAL_STRING(php_get_input_encoding());
} else if (!strcasecmp("output_encoding", type)) {
RETVAL_STRING(get_output_encoding());
RETVAL_STRING(php_get_output_encoding());
} else if (!strcasecmp("internal_encoding", type)) {
RETVAL_STRING(get_internal_encoding());
RETVAL_STRING(php_get_internal_encoding());
} else {
RETURN_FALSE;
}
Expand Down
4 changes: 3 additions & 1 deletion ext/iconv/iconv.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function iconv_mime_decode_headers(string $headers, int $mode = 0, ?string $char

function iconv(string $in_charset, string $out_charset, string $str): string|false {}

/** @deprecated */
function iconv_set_encoding(string $type, string $charset): bool {}

function iconv_get_encoding(string $type = "all"): array|string|false {}
/** @deprecated */
function iconv_get_encoding(string $type = 'all'): array|string|false {}
8 changes: 4 additions & 4 deletions ext/iconv/iconv_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 4e26168b04450adf510a4e638184c46757679ac1 */
* Stub hash: c299905ab2225a1d5d4f3dff5dbab019ccbb18b4 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_strlen, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
Expand Down Expand Up @@ -56,7 +56,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_iconv_set_encoding, 0, 2, _IS_BO
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_iconv_get_encoding, 0, 0, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\"all\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_STRING, 0, "\'all\'")
ZEND_END_ARG_INFO()


Expand All @@ -81,7 +81,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(iconv_mime_decode, arginfo_iconv_mime_decode)
ZEND_FE(iconv_mime_decode_headers, arginfo_iconv_mime_decode_headers)
ZEND_FE(iconv, arginfo_iconv)
ZEND_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
ZEND_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
ZEND_DEP_FE(iconv_set_encoding, arginfo_iconv_set_encoding)
ZEND_DEP_FE(iconv_get_encoding, arginfo_iconv_get_encoding)
ZEND_FE_END
};
12 changes: 0 additions & 12 deletions ext/iconv/php_iconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ PHP_FUNCTION(iconv_mime_encode);
PHP_FUNCTION(iconv_mime_decode);
PHP_FUNCTION(iconv_mime_decode_headers);

ZEND_BEGIN_MODULE_GLOBALS(iconv)
char *input_encoding;
char *internal_encoding;
char *output_encoding;
ZEND_END_MODULE_GLOBALS(iconv)

#define ICONVG(v) ZEND_MODULE_GLOBALS_ACCESSOR(iconv, v)

#if defined(ZTS) && defined(COMPILE_DL_ICONV)
ZEND_TSRMLS_CACHE_EXTERN()
#endif

#ifdef HAVE_IBM_ICONV
# define ICONV_ASCII_ENCODING "IBM-850"
# define ICONV_UCS4_ENCODING "UCS-4"
Expand Down
Loading