Skip to content

Fix UNKNOWN default values in various extensions #5514

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

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
#define Z_PARAM_BOOL(dest) \
Z_PARAM_BOOL_EX(dest, _dummy, 0, 0)

#define Z_PARAM_BOOL_OR_NULL(dest, is_null) \
Z_PARAM_BOOL_EX(dest, is_null, 1, 0)

/* old "C" */
#define Z_PARAM_CLASS_EX2(dest, check_null, deref, separate) \
Z_PARAM_PROLOGUE(deref, separate); \
Expand Down Expand Up @@ -1558,6 +1561,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
#define Z_PARAM_STR(dest) \
Z_PARAM_STR_EX(dest, 0, 0)

#define Z_PARAM_STR_OR_NULL(dest) \
Z_PARAM_STR_EX(dest, 1, 0)

/* old "z" */
#define Z_PARAM_ZVAL_EX2(dest, check_null, deref, separate) \
Z_PARAM_PROLOGUE(deref, separate); \
Expand Down
7 changes: 3 additions & 4 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ public function getFeature(string $feature, string $version) {}
public function hasFeature(string $feature, string $version) {}

/** @return DOMDocumentType|false */
public function createDocumentType(
string $qualifiedName, string $publicId = "", string $systemId = "") {}
public function createDocumentType(string $qualifiedName, string $publicId = "", string $systemId = "") {}

/** @return DOMDocument|false */
public function createDocument(string $namespaceURI = "", string $qualifiedName = "", DOMDocumentType $doctype = UNKNOWN) {}
public function createDocument(string $namespaceURI = "", string $qualifiedName = "", ?DOMDocumentType $doctype = null) {}
}

class DOMDocumentFragment implements DOMParentNode
Expand Down Expand Up @@ -248,7 +247,7 @@ public function prepend(...$nodes): void {}

class DOMDocument implements DOMParentNode
{
public function __construct(string $version = "1.0", string $encoding = UNKNOWN) {}
public function __construct(string $version = "1.0", string $encoding = "") {}

/** @return DOMAttr|false */
public function createAttribute(string $name) {}
Expand Down
4 changes: 2 additions & 2 deletions ext/dom/php_dom_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMImplementation_createDocument, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, namespaceURI, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, qualifiedName, IS_STRING, 0, "\"\"")
ZEND_ARG_OBJ_INFO(0, doctype, DOMDocumentType, 0)
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, doctype, DOMDocumentType, 1, "null")
ZEND_END_ARG_INFO()

#define arginfo_class_DOMDocumentFragment___construct arginfo_class_DOMNode_getLineNo
Expand Down Expand Up @@ -244,7 +244,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMDocument___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, version, IS_STRING, 0, "\"1.0\"")
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 0, "\"\"")
ZEND_END_ARG_INFO()

#define arginfo_class_DOMDocument_createAttribute arginfo_class_DOMElement_getAttribute
Expand Down
2 changes: 1 addition & 1 deletion ext/enchant/enchant.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,9 @@ PHP_FUNCTION(enchant_dict_quick_check)
enchant_dict_free_string_list(pdict->pdict, suggs);
}


RETURN_FALSE;
}

RETURN_TRUE;
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion ext/enchant/enchant.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function enchant_broker_set_ordering($broker, string $tag, string $ordering): bo
function enchant_broker_describe($broker): array {}

/** @param resource $dict */
function enchant_dict_quick_check($dict, string $word, &$suggestions = UNKNOWN): bool {}
function enchant_dict_quick_check($dict, string $word, &$suggestions = null): bool {}

/** @param resource $dict */
function enchant_dict_check($dict, string $word): bool {}
Expand Down
2 changes: 1 addition & 1 deletion ext/enchant/enchant_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_quick_check, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, dict)
ZEND_ARG_TYPE_INFO(0, word, IS_STRING, 0)
ZEND_ARG_INFO(1, suggestions)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, suggestions, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enchant_dict_check, 0, 2, _IS_BOOL, 0)
Expand Down
4 changes: 2 additions & 2 deletions ext/ffi/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_STR(code)
Z_PARAM_STR(lib)
Z_PARAM_STR_OR_NULL(lib)
ZEND_PARSE_PARAMETERS_END();

if (lib) {
Expand All @@ -2854,7 +2854,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
FFI_G(symbols) = NULL;
FFI_G(tags) = NULL;

if (code) {
if (code && ZSTR_LEN(code)) {
/* Parse C definitions */
FFI_G(default_type_attr) = ZEND_FFI_ATTR_STORED;

Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/ffi.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class FFI
{
public static function cdef(string $code = UNKNOWN, string $lib = UNKNOWN): FFI {}
public static function cdef(string $code = "", ?string $lib = null): FFI {}

public static function load(string $filename): ?FFI {}

Expand Down
4 changes: 2 additions & 2 deletions ext/ffi/ffi_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0)
ZEND_ARG_TYPE_INFO(0, code, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, lib, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, lib, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_load, 0, 1, FFI, 1)
Expand Down
2 changes: 1 addition & 1 deletion ext/ftp/ftp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function ftp_rmdir($ftp, string $directory): bool {}
function ftp_chmod($ftp, int $mode, string $filename): int|false {}

/** @param resource $ftp */
function ftp_alloc($ftp, int $size, &$response = UNKNOWN): bool {}
function ftp_alloc($ftp, int $size, &$response = null): bool {}

/** @param resource $ftp */
function ftp_nlist($ftp, string $directory): array|false {}
Expand Down
2 changes: 1 addition & 1 deletion ext/ftp/ftp_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_alloc, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, ftp)
ZEND_ARG_TYPE_INFO(0, size, IS_LONG, 0)
ZEND_ARG_INFO(1, response)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, response, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_nlist, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE)
Expand Down
4 changes: 2 additions & 2 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ PHP_FUNCTION(hash_update_file)
{
zval *zhash, *zcontext = NULL;
php_hashcontext_object *hash;
php_stream_context *context;
php_stream_context *context = NULL;
php_stream *stream;
zend_string *filename;
char buf[1024];
ssize_t n;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP|r", &zhash, php_hashcontext_ce, &filename, &zcontext) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OP|r!", &zhash, php_hashcontext_ce, &filename, &zcontext) == FAILURE) {
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/hash/hash.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ function hash_hmac(string $algo, string $data, string $key, bool $raw_output = f

function hash_hmac_file(string $algo, string $data, string $key, bool $raw_output = false): string|false {}

function hash_init(string $algo, int $options = 0, string $key = UNKNOWN): HashContext {}
function hash_init(string $algo, int $options = 0, string $key = ""): HashContext {}

function hash_update(HashContext $context, string $data): bool {}

/** @param resource $handle */
function hash_update_stream(HashContext $context, $handle, int $length = -1): int {}

/** @param resource $stream_context */
function hash_update_file(HashContext $context, string $filename, $stream_context = UNKNOWN): bool {}
function hash_update_file(HashContext $context, string $filename, $stream_context = null): bool {}

function hash_final(HashContext $context, bool $raw_output = false): string {}

Expand Down
4 changes: 2 additions & 2 deletions ext/hash/hash_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_hash_init, 0, 1, HashContext, 0)
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, key, IS_STRING, 0, "\"\"")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_update, 0, 2, _IS_BOOL, 0)
Expand All @@ -41,7 +41,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_update_file, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, context, HashContext, 0)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
ZEND_ARG_INFO(0, stream_context)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, stream_context, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_final, 0, 1, IS_STRING, 0)
Expand Down
60 changes: 36 additions & 24 deletions ext/iconv/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1826,20 +1826,22 @@ static void _php_iconv_show_error(php_iconv_err_t err, const char *out_charset,
Returns the character count of str */
PHP_FUNCTION(iconv_strlen)
{
const char *charset = get_internal_encoding();
size_t charset_len = 0;
const char *charset = NULL;
size_t charset_len;
zend_string *str;

php_iconv_err_t err;

size_t retval;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|s",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|s!",
&str, &charset, &charset_len) == FAILURE) {
RETURN_THROWS();
}

if (charset_len >= ICONV_CSNMAXLEN) {
if (charset == NULL) {
charset = 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 All @@ -1858,8 +1860,8 @@ PHP_FUNCTION(iconv_strlen)
Returns specified part of a string */
PHP_FUNCTION(iconv_substr)
{
const char *charset = get_internal_encoding();
size_t charset_len = 0;
const char *charset = NULL;
size_t charset_len;
zend_string *str;
zend_long offset, length = 0;
zend_bool len_is_null = 1;
Expand All @@ -1868,13 +1870,15 @@ PHP_FUNCTION(iconv_substr)

smart_str retval = {0};

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l!s",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sl|l!s!",
&str, &offset, &length, &len_is_null,
&charset, &charset_len) == FAILURE) {
RETURN_THROWS();
}

if (charset_len >= ICONV_CSNMAXLEN) {
if (charset == NULL) {
charset = 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 All @@ -1898,8 +1902,8 @@ PHP_FUNCTION(iconv_substr)
Finds position of first occurrence of needle within part of haystack beginning with offset */
PHP_FUNCTION(iconv_strpos)
{
const char *charset = get_internal_encoding();
size_t charset_len = 0, haystk_len;
const char *charset = NULL;
size_t charset_len, haystk_len;
zend_string *haystk;
zend_string *ndl;
zend_long offset = 0;
Expand All @@ -1908,13 +1912,15 @@ PHP_FUNCTION(iconv_strpos)

size_t retval;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|ls",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|ls!",
&haystk, &ndl,
&offset, &charset, &charset_len) == FAILURE) {
RETURN_THROWS();
}

if (charset_len >= ICONV_CSNMAXLEN) {
if (charset == NULL) {
charset = 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 @@ -1953,16 +1959,16 @@ PHP_FUNCTION(iconv_strpos)
Finds position of last occurrence of needle within part of haystack beginning with offset */
PHP_FUNCTION(iconv_strrpos)
{
const char *charset = get_internal_encoding();
size_t charset_len = 0;
const char *charset = NULL;
size_t charset_len;
zend_string *haystk;
zend_string *ndl;

php_iconv_err_t err;

size_t retval;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|s",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|s!",
&haystk, &ndl,
&charset, &charset_len) == FAILURE) {
RETURN_THROWS();
Expand All @@ -1972,7 +1978,9 @@ PHP_FUNCTION(iconv_strrpos)
RETURN_FALSE;
}

if (charset_len >= ICONV_CSNMAXLEN) {
if (charset == NULL) {
charset = 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 @@ -2097,21 +2105,23 @@ PHP_FUNCTION(iconv_mime_encode)
PHP_FUNCTION(iconv_mime_decode)
{
zend_string *encoded_str;
const char *charset = get_internal_encoding();
size_t charset_len = 0;
const char *charset = NULL;
size_t charset_len;
zend_long mode = 0;

smart_str retval = {0};

php_iconv_err_t err;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls!",
&encoded_str, &mode, &charset, &charset_len) == FAILURE) {

RETURN_THROWS();
}

if (charset_len >= ICONV_CSNMAXLEN) {
if (charset == NULL) {
charset = 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 All @@ -2137,21 +2147,23 @@ PHP_FUNCTION(iconv_mime_decode)
PHP_FUNCTION(iconv_mime_decode_headers)
{
zend_string *encoded_str;
const char *charset = get_internal_encoding();
size_t charset_len = 0;
const char *charset = NULL;
size_t charset_len;
zend_long mode = 0;
char *enc_str_tmp;
size_t enc_str_len_tmp;

php_iconv_err_t err = PHP_ICONV_ERR_SUCCESS;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls",
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|ls!",
&encoded_str, &mode, &charset, &charset_len) == FAILURE) {

RETURN_THROWS();
}

if (charset_len >= ICONV_CSNMAXLEN) {
if (charset == NULL) {
charset = 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
14 changes: 7 additions & 7 deletions ext/iconv/iconv.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

/** @generate-function-entries */

function iconv_strlen(string $str, string $charset = UNKNOWN): int|false {}
function iconv_strlen(string $str, ?string $charset = null): int|false {}

function iconv_substr(string $str, int $offset, ?int $length = null, string $charset = UNKNOWN): string|false {}
function iconv_substr(string $str, int $offset, ?int $length = null, ?string $charset = null): string|false {}

function iconv_strpos(string $haystack, string $needle, int $offset = 0, string $charset = UNKNOWN): int|false {}
function iconv_strpos(string $haystack, string $needle, int $offset = 0, ?string $charset = null): int|false {}

function iconv_strrpos(string $haystack, string $needle, string $charset = UNKNOWN): int|false {}
function iconv_strrpos(string $haystack, string $needle, ?string $charset = null): int|false {}

function iconv_mime_encode(string $field_name, string $field_value, array $preference = []): string|false {}

function iconv_mime_decode(string $encoded_string, int $mode = 0, string $charset = UNKNOWN): string|false {}
function iconv_mime_decode(string $encoded_string, int $mode = 0, ?string $charset = null): string|false {}

function iconv_mime_decode_headers(string $headers, int $mode = 0, string $charset = UNKNOWN): array|false {}
function iconv_mime_decode_headers(string $headers, int $mode = 0, ?string $charset = null): array|false {}

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

function iconv_set_encoding(string $type, string $charset): bool {}

function iconv_get_encoding(string $type = 'all'): array|string|false {}
function iconv_get_encoding(string $type = "all"): array|string|false {}
Loading