Skip to content

Commit 35ad13f

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/sockets: memory related issues fix.
2 parents e193897 + 754ea6e commit 35ad13f

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
@@ -1207,6 +1207,7 @@ static void to_zval_read_iov(const char *msghdr_c, zval *zv, res_context *ctx)
12071207
if (iovlen > UINT_MAX) {
12081208
do_to_zval_err(ctx, "unexpectedly large value for iov_len: %lu",
12091209
(unsigned long)iovlen);
1210+
return;
12101211
}
12111212
array_init_size(zv, (uint32_t)iovlen);
12121213

ext/sockets/multicast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ zend_result php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struc
654654
retry:
655655
retval = GetIpAddrTable(addr_table, &size, 0);
656656
if (retval == ERROR_INSUFFICIENT_BUFFER) {
657-
erealloc(addr_table, size);
657+
addr_table = erealloc(addr_table, size);
658658
goto retry;
659659
}
660660
if (retval != NO_ERROR) {
@@ -696,7 +696,7 @@ zend_result php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, uns
696696
retry:
697697
retval = GetIpAddrTable(addr_table, &size, 0);
698698
if (retval == ERROR_INSUFFICIENT_BUFFER) {
699-
erealloc(addr_table, size);
699+
addr_table = erealloc(addr_table, size);
700700
goto retry;
701701
}
702702
if (retval != NO_ERROR) {

ext/sockets/sockets.c

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

20132013
optlen = sizeof(other_val);
2014+
other_val = 0;
20142015

20152016
if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&other_val, &optlen) != 0) {
20162017
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
@@ -2036,6 +2037,10 @@ PHP_FUNCTION(socket_set_option)
20362037
DWORD timeout;
20372038
#else
20382039
struct timeval tv;
2040+
#endif
2041+
#ifdef SO_ATTACH_REUSEPORT_CBPF
2042+
struct sock_filter cbpf[8] = {0};
2043+
struct sock_fprog bpfprog;
20392044
#endif
20402045
zend_long level, optname;
20412046
void *opt_ptr;
@@ -2302,8 +2307,6 @@ PHP_FUNCTION(socket_set_option)
23022307
optname = SO_DETACH_BPF;
23032308
} else {
23042309
uint32_t k = (uint32_t)cbpf_val;
2305-
static struct sock_filter cbpf[8] = {0};
2306-
static struct sock_fprog bpfprog;
23072310

23082311
switch (k) {
23092312
case SKF_AD_CPU:
@@ -2602,6 +2605,7 @@ PHP_FUNCTION(socket_import_stream)
26022605
retsock = Z_SOCKET_P(return_value);
26032606

26042607
if (!socket_import_file_descriptor(socket, retsock)) {
2608+
retsock->bsd_socket = -1;
26052609
zval_ptr_dtor(return_value);
26062610
RETURN_FALSE;
26072611
}

0 commit comments

Comments
 (0)