Skip to content

Commit 9ecb367

Browse files
committed
forgotten test and fix bugs
1 parent 087aa3a commit 9ecb367

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

ext/sockets/sockets.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,9 +2319,17 @@ PHP_FUNCTION(socket_set_option)
23192319
zend_object *so_splice_obj = Z_OBJ_P(arg4);
23202320
zval tmpA, tmpB, tmpC;
23212321

2322-
zval *socket = zend_read_property(socket_so_splice_ce, so_splice_obj, "socket", strlen("socket"), 0, &tmpA);
2323-
zval *max = zend_read_property(socket_so_splice_ce, so_splice_obj, "max", strlen("max"), 0, &tmpB);
2324-
zval *array = zend_read_property(socket_so_splice_ce, so_splice_obj, "time", strlen("time"), 0, &tmpC);
2322+
zval *socket = zend_read_property(socket_so_splice_ce, so_splice_obj, "socket", strlen("socket"), false, &tmpA);
2323+
if (Z_TYPE_P(socket) == IS_NULL) {
2324+
zend_argument_type_error(4, "invalid SocketSoSplice socket member value");
2325+
RETURN_THROWS();
2326+
}
2327+
zval *max = zend_read_property(socket_so_splice_ce, so_splice_obj, "max", strlen("max"), false, &tmpB);
2328+
zval *array = zend_read_property(socket_so_splice_ce, so_splice_obj, "time", strlen("time"), false, &tmpC);
2329+
if (Z_TYPE_P(array) == IS_NULL) {
2330+
zend_argument_type_error(4, "invalid SocketSoSplice time member value");
2331+
RETURN_THROWS();
2332+
}
23252333

23262334
php_socket *php_sock = Z_SOCKET_P(socket);
23272335
zend_long php_max = Z_LVAL_P(max);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
SO_SPLICE usage with socket_set_option
3+
--EXTENSIONS--
4+
sockets
5+
--SKIPIF--
6+
<?php
7+
8+
if (!defined('SO_SPLICE')) {
9+
die('skip SO_SPLICE not available.');
10+
}
11+
12+
?>
13+
--FILE--
14+
<?php
15+
class badClass {}
16+
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
17+
$todrain = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
18+
19+
try {
20+
socket_set_option($socket, SOL_SOCKET, SO_SPLICE, $todrain);
21+
} catch (\TypeError $e) {
22+
echo $e->getMessage(), PHP_EOL;
23+
}
24+
25+
try {
26+
socket_set_option($socket, SOL_SOCKET, SO_SPLICE, new badClass());
27+
} catch (\TypeError $e) {
28+
echo $e->getMessage(), PHP_EOL;
29+
}
30+
31+
try {
32+
$s = new SocketSoSplice();
33+
$s->max = -1;
34+
$s->socket = $todrain;
35+
$s->time = ["sec" => 0, "usec" => 0];
36+
socket_set_option($socket, SOL_SOCKET, SO_SPLICE, $s);
37+
} catch (\ValueError $e) {
38+
echo $e->getMessage(), PHP_EOL;
39+
}
40+
41+
socket_close($todrain);
42+
socket_close($socket);
43+
?>
44+
--EXPECT--
45+
socket_set_option(): Argument #4 ($value) must be of type SocketSoSplice, Socket given
46+
socket_set_option(): Argument #4 ($value) must be of type SocketSoSplice, badClass given
47+
socket_set_option(): Argument #4 ($value) "max" key must be greater than or equal to 0

0 commit comments

Comments
 (0)