Skip to content

Commit 459a2ce

Browse files
committed
fix object creation
1 parent 54bf792 commit 459a2ce

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
@@ -1653,10 +1653,11 @@ PHP_FUNCTION(socket_recvfrom)
16531653
unsigned short protocol = ntohs(e->h_proto);
16541654
unsigned char *payload = ((unsigned char *)e + sizeof(struct ethhdr));
16551655

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

16621663
switch (protocol) {
@@ -1711,10 +1712,14 @@ PHP_FUNCTION(socket_recvfrom)
17111712
RETURN_THROWS();
17121713
}
17131714

1714-
zend_update_property(Z_OBJCE_P(arg2), Z_OBJ_P(arg2), ZEND_STRL("payload"), &zpayload);
1715+
zend_update_property(Z_OBJCE(obj), Z_OBJ(obj), ZEND_STRL("payload"), &zpayload);
17151716

1717+
ZEND_TRY_ASSIGN_REF_COPY(arg2, &obj);
17161718
ZEND_TRY_ASSIGN_REF_STRING(arg5, ifrname);
1717-
ZEND_TRY_ASSIGN_REF_LONG(arg6, sll.sll_ifindex);
1719+
1720+
if (arg6) {
1721+
ZEND_TRY_ASSIGN_REF_LONG(arg6, sll.sll_ifindex);
1722+
}
17181723
break;
17191724
#endif
17201725
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)