Skip to content

Commit fd1c0f4

Browse files
committed
fix object creation
1 parent 8abcb80 commit fd1c0f4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

ext/sockets/sockets.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,10 +1655,11 @@ PHP_FUNCTION(socket_recvfrom)
16551655
unsigned short protocol = ntohs(e->h_proto);
16561656
unsigned char *payload = ((unsigned char *)e + sizeof(struct ethhdr));
16571657

1658-
object_init_ex(arg2, socket_ethinfo_ce);
1659-
zend_update_property_string(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("macsrc"), ether_ntoa((struct ether_addr *)e->h_source));
1660-
zend_update_property_string(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("macdst"), ether_ntoa((struct ether_addr *)e->h_dest));
1661-
zend_update_property_long(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("ethprotocol"), protocol);
1658+
zval obj;
1659+
object_init_ex(&obj, socket_ethinfo_ce);
1660+
zend_update_property_string(Z_OBJCE(obj), Z_OBJ(obj), ZEND_STRL("macsrc"), ether_ntoa((struct ether_addr *)e->h_source));
1661+
zend_update_property_string(Z_OBJCE(obj), Z_OBJ(obj), ZEND_STRL("macdst"), ether_ntoa((struct ether_addr *)e->h_dest));
1662+
zend_update_property_long(Z_OBJCE(obj), Z_OBJ(obj), ZEND_STRL("ethprotocol"), protocol);
16621663
array_init(&zpayload);
16631664

16641665
switch (protocol) {
@@ -1713,10 +1714,14 @@ PHP_FUNCTION(socket_recvfrom)
17131714
RETURN_THROWS();
17141715
}
17151716

1716-
zend_update_property(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("payload"), &zpayload);
1717+
zend_update_property(Z_OBJCE(obj), Z_OBJ(obj), ZEND_STRL("payload"), &zpayload);
17171718

1719+
ZEND_TRY_ASSIGN_REF_COPY(arg2, &obj);
17181720
ZEND_TRY_ASSIGN_REF_STRING(arg5, ifrname);
1719-
ZEND_TRY_ASSIGN_REF_LONG(arg6, sll.sll_ifindex);
1721+
1722+
if (arg6) {
1723+
ZEND_TRY_ASSIGN_REF_LONG(arg6, sll.sll_ifindex);
1724+
}
17201725
break;
17211726
#endif
17221727
default:

ext/sockets/tests/socket_afpacket.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ if (!function_exists("posix_getuid") || posix_getuid() != 0) {
3030
$s_s = socket_create(AF_PACKET, SOCK_RAW, ETH_P_ALL);
3131
$v_bind = socket_bind($s_s, 'lo');
3232

33-
$buf = str_pad(str_repeat("0", ETH_FRAME_LEN) .
33+
$buf = str_repeat("0", ETH_FRAME_LEN) .
3434
str_repeat("\xFF", 6) .
3535
str_repeat("\x11", 6) .
36-
"\x08\x00TEST ethernet", 2048, "\x00");
36+
"\x08\x00" .
37+
str_pad(str_repeat("test", 512), 2048, "\x00");
3738

3839
var_dump(socket_sendto($s_s, $buf, strlen($buf), 0, "lo", 1));
3940

@@ -47,4 +48,4 @@ string(2) "lo"
4748
int(%i)
4849

4950
Warning: socket_getpeername(): unable to retrieve peer name [95]: %sot supported in %s on line %d
50-
int(2048)
51+
int(3576)

0 commit comments

Comments
 (0)