Skip to content

Commit

Permalink
Merge branch 'PHP-8.3' into PHP-8.4
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix crashes in enchant when passing null bytes
  • Loading branch information
nielsdos committed Jan 8, 2025
2 parents 6d21598 + 783ecad commit 91384e5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ PHP NEWS
- DOM:
. Fixed bug GH-17397 (Assertion failure ext/dom/php_dom.c). (nielsdos)

- Enchant:
. Fix crashes in enchant when passing null bytes. (nielsdos)

- FTP:
. Fixed bug GH-16800 (ftp functions can abort with EINTR). (nielsdos)

Expand Down
22 changes: 11 additions & 11 deletions ext/enchant/enchant.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ PHP_FUNCTION(enchant_broker_set_dict_path)
char *value;
size_t value_len;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ols", &broker, enchant_broker_ce, &dict_type, &value, &value_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olp", &broker, enchant_broker_ce, &dict_type, &value, &value_len) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -440,7 +440,7 @@ PHP_FUNCTION(enchant_broker_request_dict)
char *tag;
size_t taglen;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &broker, enchant_broker_ce, &tag, &taglen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &broker, enchant_broker_ce, &tag, &taglen) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -534,7 +534,7 @@ PHP_FUNCTION(enchant_broker_dict_exists)
size_t taglen;
enchant_broker * pbroker;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &broker, enchant_broker_ce, &tag, &taglen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &broker, enchant_broker_ce, &tag, &taglen) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -559,7 +559,7 @@ PHP_FUNCTION(enchant_broker_set_ordering)
size_t ptaglen;
enchant_broker * pbroker;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss", &broker, enchant_broker_ce, &ptag, &ptaglen, &pordering, &porderinglen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opp", &broker, enchant_broker_ce, &ptag, &ptaglen, &pordering, &porderinglen) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -597,7 +597,7 @@ PHP_FUNCTION(enchant_dict_quick_check)
size_t wordlen;
enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os|z", &dict, enchant_dict_ce, &word, &wordlen, &sugg) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op|z", &dict, enchant_dict_ce, &word, &wordlen, &sugg) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -642,7 +642,7 @@ PHP_FUNCTION(enchant_dict_check)
size_t wordlen;
enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -662,7 +662,7 @@ PHP_FUNCTION(enchant_dict_suggest)
enchant_dict *pdict;
size_t n_sugg;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -690,7 +690,7 @@ PHP_FUNCTION(enchant_dict_add)
size_t wordlen;
enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -708,7 +708,7 @@ PHP_FUNCTION(enchant_dict_add_to_session)
size_t wordlen;
enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -726,7 +726,7 @@ PHP_FUNCTION(enchant_dict_is_added)
size_t wordlen;
enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Op", &dict, enchant_dict_ce, &word, &wordlen) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -748,7 +748,7 @@ PHP_FUNCTION(enchant_dict_store_replacement)

enchant_dict *pdict;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oss", &dict, enchant_dict_ce, &mis, &mislen, &cor, &corlen) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opp", &dict, enchant_dict_ce, &mis, &mislen, &cor, &corlen) == FAILURE) {
RETURN_THROWS();
}

Expand Down
70 changes: 70 additions & 0 deletions ext/enchant/tests/null_bytes.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--TEST--
null bytes
--EXTENSIONS--
enchant
--SKIPIF--
<?php
$broker = enchant_broker_init();
if (!enchant_broker_list_dicts($broker)) die("skip No broker dicts installed");
?>
--FILE--
<?php

$broker = enchant_broker_init();
$dicts = enchant_broker_list_dicts($broker);
$requestDict = enchant_broker_request_dict($broker, $dicts[0]['lang_tag']);

$two_params_broker = [
"enchant_broker_request_dict",
"enchant_broker_dict_exists",
];

$two_params_dict = [
"enchant_dict_quick_check",
"enchant_dict_check",
"enchant_dict_suggest",
"enchant_dict_add",
"enchant_dict_add_to_session",
"enchant_dict_is_added",
];

foreach ($two_params_broker as $func) {
try {
$func($broker, "foo\0bar");
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
}

foreach ($two_params_dict as $func) {
try {
$func($requestDict, "foo\0bar");
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
}

try {
var_dump(enchant_broker_set_ordering($broker, "foo\0bar", "foo\0bar"));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

try {
var_dump(enchant_dict_store_replacement($requestDict, "foo\0bar", "foo\0bar"));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
enchant_broker_request_dict(): Argument #2 ($tag) must not contain any null bytes
enchant_broker_dict_exists(): Argument #2 ($tag) must not contain any null bytes
enchant_dict_quick_check(): Argument #2 ($word) must not contain any null bytes
enchant_dict_check(): Argument #2 ($word) must not contain any null bytes
enchant_dict_suggest(): Argument #2 ($word) must not contain any null bytes
enchant_dict_add(): Argument #2 ($word) must not contain any null bytes
enchant_dict_add_to_session(): Argument #2 ($word) must not contain any null bytes
enchant_dict_is_added(): Argument #2 ($word) must not contain any null bytes
enchant_broker_set_ordering(): Argument #2 ($tag) must not contain any null bytes
enchant_dict_store_replacement(): Argument #2 ($misspelled) must not contain any null bytes

0 comments on commit 91384e5

Please sign in to comment.