Fix missing empty string checks in ext/enchant

The library requires the tags to be non-empty, and also requires the
ordering to be non-empty. For the tags, otherwise, assertion failures
can be observed.

Closes GH-18733.
This commit is contained in:
Niels Dossche 2025-06-01 18:45:04 +02:00
parent b871261c10
commit 88f546b166
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
4 changed files with 56 additions and 0 deletions

1
NEWS
View file

@ -71,6 +71,7 @@ PHP NEWS
- Enchant: - Enchant:
. Added enchant_dict_remove_from_session(). (nielsdos) . Added enchant_dict_remove_from_session(). (nielsdos)
. Added enchant_dict_remove(). (nielsdos) . Added enchant_dict_remove(). (nielsdos)
. Fix missing empty string checks. (nielsdos)
- EXIF: - EXIF:
. Add OffsetTime* Exif tags. (acc987) . Add OffsetTime* Exif tags. (acc987)

View file

@ -529,6 +529,11 @@ PHP_FUNCTION(enchant_broker_dict_exists)
PHP_ENCHANT_GET_BROKER; PHP_ENCHANT_GET_BROKER;
if (taglen == 0) {
zend_argument_must_not_be_empty_error(2);
RETURN_THROWS();
}
RETURN_BOOL(enchant_broker_dict_exists(pbroker->pbroker, tag)); RETURN_BOOL(enchant_broker_dict_exists(pbroker->pbroker, tag));
} }
/* }}} */ /* }}} */
@ -554,6 +559,16 @@ PHP_FUNCTION(enchant_broker_set_ordering)
PHP_ENCHANT_GET_BROKER; PHP_ENCHANT_GET_BROKER;
if (ptaglen == 0) {
zend_argument_must_not_be_empty_error(2);
RETURN_THROWS();
}
if (porderinglen == 0) {
zend_argument_must_not_be_empty_error(3);
RETURN_THROWS();
}
enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering); enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering);
RETURN_TRUE; RETURN_TRUE;
} }

View file

@ -0,0 +1,17 @@
--TEST--
enchant_broker_dict_exists() function - empty tag
--EXTENSIONS--
enchant
--FILE--
<?php
$broker = enchant_broker_init();
try {
enchant_broker_dict_exists($broker, '');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
echo "Done\n";
?>
--EXPECT--
enchant_broker_dict_exists(): Argument #2 ($tag) must not be empty
Done

View file

@ -0,0 +1,23 @@
--TEST--
enchant_broker_set_ordering() function - empty tag
--EXTENSIONS--
enchant
--FILE--
<?php
$broker = enchant_broker_init();
try {
enchant_broker_set_ordering($broker, '', '');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
try {
enchant_broker_set_ordering($broker, '*', '');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
echo "Done\n";
?>
--EXPECT--
enchant_broker_set_ordering(): Argument #2 ($tag) must not be empty
enchant_broker_set_ordering(): Argument #3 ($ordering) must not be empty
Done