Skip to content

Commit 3b798a9

Browse files
committed
changes from feedback
1 parent f54f464 commit 3b798a9

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

ext/session/session.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,6 @@ PHP_FUNCTION(session_start)
26342634
{
26352635
zval *options = NULL;
26362636
zval *value;
2637-
zend_ulong num_idx;
26382637
zend_string *str_idx;
26392638
bool read_and_close = false;
26402639

@@ -2660,19 +2659,27 @@ PHP_FUNCTION(session_start)
26602659
/* set options */
26612660
if (options) {
26622661
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();
26652662
}
26662663

2667-
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(options), num_idx, str_idx, value) {
2664+
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), str_idx, value) {
26682665
if (str_idx) {
26692666
switch(Z_TYPE_P(value)) {
26702667
case IS_STRING:
26712668
case IS_TRUE:
26722669
case IS_FALSE:
26732670
case IS_LONG:
26742671
if (zend_string_equals_literal(str_idx, "read_and_close")) {
2675-
zend_long tmp = zval_get_long_ex(value, true);
2672+
zend_long tmp;
2673+
if (Z_TYPE_P(value) != IS_STRING) {
2674+
tmp = zval_get_long(value);
2675+
} else {
2676+
if (is_numeric_string(Z_STRVAL_P(value), Z_STRLEN_P(value), &tmp, NULL, false) != IS_LONG) {
2677+
zend_type_error("%s(): Option \"%s\" value must be of type compatible with int, \"%s\" given",
2678+
get_active_function_name(), ZSTR_VAL(str_idx), Z_STRVAL_P(value)
2679+
);
2680+
RETURN_THROWS();
2681+
}
2682+
}
26762683
read_and_close = (tmp > 0);
26772684
} else {
26782685
zend_string *tmp_val;
@@ -2689,8 +2696,10 @@ PHP_FUNCTION(session_start)
26892696
);
26902697
RETURN_THROWS();
26912698
}
2699+
} else {
2700+
zend_argument_value_error(1, "must be of type array with keys as string");
2701+
RETURN_THROWS();
26922702
}
2693-
(void) num_idx;
26942703
} ZEND_HASH_FOREACH_END();
26952704
}
26962705

ext/session/tests/session_start_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $read_and_close = "false";
1919

2020
try {
2121
session_start([$read_and_close]);
22-
} catch (TypeError $exception) {
22+
} catch (ValueError $exception) {
2323
echo $exception->getMessage() . "\n";
2424
}
2525

ext/session/tests/session_start_read_and_close.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ foreach ($valuesEnablingReadAndClose as $value) {
1919
}
2020

2121
foreach ($valuesDisablingReadAndClose as $value) {
22-
session_start(["read_and_close" => $value]);
22+
try {
23+
session_start(["read_and_close" => $value]);
24+
} catch (TypeError $e) {
25+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
26+
}
2327
var_dump(session_status() === PHP_SESSION_ACTIVE);
2428
session_write_close();
2529
}
@@ -43,9 +47,11 @@ bool(false)
4347
Notice: session_start(): Ignoring session_start() because a session is already active (started from %s on line %d) in %s on line %d
4448
bool(true)
4549
bool(true)
50+
TypeError: session_start(): Option "read_and_close" value must be of type compatible with int, "false" given
51+
bool(false)
4652
bool(true)
4753
bool(true)
48-
bool(true)
49-
bool(true)
54+
TypeError: session_start(): Option "read_and_close" value must be of type compatible with int, "no" given
55+
bool(false)
5056
bool(true)
5157
TypeError: session_start(): Option "read_and_close" must be of type string|int|bool, float given

0 commit comments

Comments
 (0)