Skip to content

Commit d59fdaa

Browse files
committed
forbids non SOCK_RAW socket with AF_PACKET for the moment.
1 parent eb41f3f commit d59fdaa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ext/sockets/sockets.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,9 @@ PHP_FUNCTION(socket_recvfrom)
15161516
#endif
15171517
#ifdef AF_PACKET
15181518
struct sockaddr_ll sll;
1519+
int protoid;
1520+
socklen_t protoidlen = sizeof(protoid);
1521+
15191522
#endif
15201523
char addrbuf[INET6_ADDRSTRLEN];
15211524
socklen_t slen;
@@ -1632,6 +1635,13 @@ PHP_FUNCTION(socket_recvfrom)
16321635
#endif
16331636
#ifdef AF_PACKET
16341637
case AF_PACKET:
1638+
getsockopt(php_sock->bsd_socket, SOL_SOCKET, SO_TYPE, (char *) &protoid, &protoidlen);
1639+
1640+
// TODO: SOCK_DGRAM support
1641+
if (protoid != SOCK_RAW) {
1642+
zend_argument_value_error(1, "must be SOCK_RAW socket type");
1643+
RETURN_THROWS();
1644+
}
16351645
slen = sizeof(sll);
16361646
memset(&sll, 0, sizeof(sll));
16371647
sll.sll_family = AF_PACKET;
@@ -1846,7 +1856,7 @@ PHP_FUNCTION(socket_sendto)
18461856
RETURN_THROWS();
18471857
}
18481858

1849-
halen = addr_len > ETH_ALEN ? ETH_ALEN : (unsigned char)addr_len;
1859+
halen = ZSTR_LEN(addr) > ETH_ALEN ? ETH_ALEN : (unsigned char)ZSTR_LEN(addr);
18501860

18511861
memset(&sll, 0, sizeof(sll));
18521862
memcpy(sll.sll_addr, addr, halen);

0 commit comments

Comments
 (0)