Skip to content

Commit ec391cf

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/sockets: memory related issues fix.
2 parents d9ca1c7 + 35ad13f commit ec391cf

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

ext/sockets/conversions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@ static void to_zval_read_iov(const char *msghdr_c, zval *zv, res_context *ctx)
12181218
if (iovlen > UINT_MAX) {
12191219
do_to_zval_err(ctx, "unexpectedly large value for iov_len: %lu",
12201220
(unsigned long)iovlen);
1221+
return;
12211222
}
12221223
array_init_size(zv, (uint32_t)iovlen);
12231224

ext/sockets/multicast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struc
652652
retry:
653653
retval = GetIpAddrTable(addr_table, &size, 0);
654654
if (retval == ERROR_INSUFFICIENT_BUFFER) {
655-
erealloc(addr_table, size);
655+
addr_table = erealloc(addr_table, size);
656656
goto retry;
657657
}
658658
if (retval != NO_ERROR) {
@@ -694,7 +694,7 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
694694
retry:
695695
retval = GetIpAddrTable(addr_table, &size, 0);
696696
if (retval == ERROR_INSUFFICIENT_BUFFER) {
697-
erealloc(addr_table, size);
697+
addr_table = erealloc(addr_table, size);
698698
goto retry;
699699
}
700700
if (retval != NO_ERROR) {

ext/sockets/sockets.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ PHP_FUNCTION(socket_get_option)
20322032
#endif
20332033

20342034
optlen = sizeof(other_val);
2035+
other_val = 0;
20352036

20362037
if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&other_val, &optlen) != 0) {
20372038
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
@@ -2057,6 +2058,10 @@ PHP_FUNCTION(socket_set_option)
20572058
DWORD timeout;
20582059
#else
20592060
struct timeval tv;
2061+
#endif
2062+
#ifdef SO_ATTACH_REUSEPORT_CBPF
2063+
struct sock_filter cbpf[8] = {0};
2064+
struct sock_fprog bpfprog;
20602065
#endif
20612066
zend_long level, optname;
20622067
void *opt_ptr;
@@ -2345,8 +2350,6 @@ PHP_FUNCTION(socket_set_option)
23452350
optname = SO_DETACH_BPF;
23462351
} else {
23472352
uint32_t k = (uint32_t)cbpf_val;
2348-
static struct sock_filter cbpf[8] = {0};
2349-
static struct sock_fprog bpfprog;
23502353

23512354
switch (k) {
23522355
case SKF_AD_CPU:
@@ -2645,6 +2648,7 @@ PHP_FUNCTION(socket_import_stream)
26452648
retsock = Z_SOCKET_P(return_value);
26462649

26472650
if (!socket_import_file_descriptor(socket, retsock)) {
2651+
retsock->bsd_socket = -1;
26482652
zval_ptr_dtor(return_value);
26492653
RETURN_FALSE;
26502654
}

0 commit comments

Comments
 (0)