Skip to content

Commit 4582ff8

Browse files
committed
ext/session: session_start() options arguments type checks.
1 parent f5aa69a commit 4582ff8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ext/session/session.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,7 +2636,7 @@ PHP_FUNCTION(session_start)
26362636
zval *value;
26372637
zend_ulong num_idx;
26382638
zend_string *str_idx;
2639-
zend_long read_and_close = 0;
2639+
bool read_and_close = false;
26402640

26412641
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a", &options) == FAILURE) {
26422642
RETURN_THROWS();
@@ -2659,6 +2659,11 @@ PHP_FUNCTION(session_start)
26592659

26602660
/* set options */
26612661
if (options) {
2662+
if (UNEXPECTED(HT_IS_PACKED(Z_ARRVAL_P(options)))) {
2663+
zend_argument_type_error(1, "must be of type array with keys as string");
2664+
RETURN_THROWS();
2665+
}
2666+
26622667
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) {
26632668
if (str_idx) {
26642669
switch(Z_TYPE_P(value)) {
@@ -2667,7 +2672,8 @@ PHP_FUNCTION(session_start)
26672672
case IS_FALSE:
26682673
case IS_LONG:
26692674
if (zend_string_equals_literal(str_idx, "read_and_close")) {
2670-
read_and_close = zval_get_long(value);
2675+
zend_long tmp = zval_get_long_ex(value, true);
2676+
read_and_close = (tmp > 0);
26712677
} else {
26722678
zend_string *tmp_val;
26732679
zend_string *val = zval_get_tmp_string(value, &tmp_val);

ext/session/tests/session_start_read_and_close.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ foreach ($valuesDisablingReadAndClose as $value) {
2626

2727
try {
2828
session_start(["read_and_close" => 1.0]);
29-
} catch (Throwable $e) {
29+
} catch (TypeError $e) {
3030
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
3131
}
3232

@@ -46,4 +46,4 @@ bool(true)
4646
bool(true)
4747
bool(true)
4848
bool(true)
49-
TypeError: session_start(): Option "read_and_close" must be of type string|int|bool, float given
49+
session_start(): Option "read_and_close" must be of type string|int|bool, float given

0 commit comments

Comments
 (0)