Skip to content

Commit 88f546b

Browse files
committed
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.
1 parent b871261 commit 88f546b

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ PHP NEWS
7171
- Enchant:
7272
. Added enchant_dict_remove_from_session(). (nielsdos)
7373
. Added enchant_dict_remove(). (nielsdos)
74+
. Fix missing empty string checks. (nielsdos)
7475

7576
- EXIF:
7677
. Add OffsetTime* Exif tags. (acc987)

ext/enchant/enchant.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ PHP_FUNCTION(enchant_broker_dict_exists)
529529

530530
PHP_ENCHANT_GET_BROKER;
531531

532+
if (taglen == 0) {
533+
zend_argument_must_not_be_empty_error(2);
534+
RETURN_THROWS();
535+
}
536+
532537
RETURN_BOOL(enchant_broker_dict_exists(pbroker->pbroker, tag));
533538
}
534539
/* }}} */
@@ -554,6 +559,16 @@ PHP_FUNCTION(enchant_broker_set_ordering)
554559

555560
PHP_ENCHANT_GET_BROKER;
556561

562+
if (ptaglen == 0) {
563+
zend_argument_must_not_be_empty_error(2);
564+
RETURN_THROWS();
565+
}
566+
567+
if (porderinglen == 0) {
568+
zend_argument_must_not_be_empty_error(3);
569+
RETURN_THROWS();
570+
}
571+
557572
enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering);
558573
RETURN_TRUE;
559574
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
enchant_broker_dict_exists() function - empty tag
3+
--EXTENSIONS--
4+
enchant
5+
--FILE--
6+
<?php
7+
$broker = enchant_broker_init();
8+
try {
9+
enchant_broker_dict_exists($broker, '');
10+
} catch (ValueError $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
echo "Done\n";
14+
?>
15+
--EXPECT--
16+
enchant_broker_dict_exists(): Argument #2 ($tag) must not be empty
17+
Done
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
enchant_broker_set_ordering() function - empty tag
3+
--EXTENSIONS--
4+
enchant
5+
--FILE--
6+
<?php
7+
$broker = enchant_broker_init();
8+
try {
9+
enchant_broker_set_ordering($broker, '', '');
10+
} catch (ValueError $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
try {
14+
enchant_broker_set_ordering($broker, '*', '');
15+
} catch (ValueError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
echo "Done\n";
19+
?>
20+
--EXPECT--
21+
enchant_broker_set_ordering(): Argument #2 ($tag) must not be empty
22+
enchant_broker_set_ordering(): Argument #3 ($ordering) must not be empty
23+
Done

0 commit comments

Comments
 (0)