Skip to content

socket_create_pair() can no longer return NULL #6592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 10, 2021

php-src/ext/sockets/sockets.c

Lines 1973 to 2033 in f40838e

PHP_FUNCTION(socket_create_pair)
{
zval retval[2], *fds_array_zval;
php_socket *php_sock[2];
PHP_SOCKET fds_array[2];
zend_long domain, type, protocol;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllz", &domain, &type, &protocol, &fds_array_zval) == FAILURE) {
RETURN_THROWS();
}
if (domain != AF_INET
#if HAVE_IPV6
&& domain != AF_INET6
#endif
&& domain != AF_UNIX) {
zend_argument_value_error(1, "must be one of AF_UNIX, AF_INET6, or AF_INET");
RETURN_THROWS();
}
if (type > 10) {
zend_argument_value_error(2, "must be one of SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET,"
" SOCK_RAW, or SOCK_RDM");
RETURN_THROWS();
}
object_init_ex(&retval[0], socket_ce);
php_sock[0] = Z_SOCKET_P(&retval[0]);
object_init_ex(&retval[1], socket_ce);
php_sock[1] = Z_SOCKET_P(&retval[1]);
if (socketpair(domain, type, protocol, fds_array) != 0) {
SOCKETS_G(last_error) = errno;
php_error_docref(NULL, E_WARNING, "Unable to create socket pair [%d]: %s", errno, sockets_strerror(errno));
zval_ptr_dtor(&retval[0]);
zval_ptr_dtor(&retval[1]);
RETURN_FALSE;
}
fds_array_zval = zend_try_array_init(fds_array_zval);
if (!fds_array_zval) {
zval_ptr_dtor(&retval[0]);
zval_ptr_dtor(&retval[1]);
RETURN_THROWS();
}
php_sock[0]->bsd_socket = fds_array[0];
php_sock[1]->bsd_socket = fds_array[1];
php_sock[0]->type = domain;
php_sock[1]->type = domain;
php_sock[0]->error = 0;
php_sock[1]->error = 0;
php_sock[0]->blocking = 1;
php_sock[1]->blocking = 1;
add_index_zval(fds_array_zval, 0, &retval[0]);
add_index_zval(fds_array_zval, 1, &retval[1]);
RETURN_TRUE;
}

@php-pulls php-pulls closed this in 41e9a8e Jan 12, 2021
@cmb69 cmb69 deleted the cmb/sockets-stub-fix branch January 28, 2021 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants