diff options
author | Gustavo André dos Santos Lopes <cataphract@php.net> | 2011-03-17 15:36:52 +0000 |
---|---|---|
committer | Gustavo André dos Santos Lopes <cataphract@php.net> | 2011-03-17 15:36:52 +0000 |
commit | be87834321151d908d9dc879e8d3e462fc67b733 (patch) | |
tree | f82df2388256906c79dde828a2374f3f524fdf96 /ext/sockets | |
parent | 8bbd451647f48542f27cef4da1439646ea8e8df3 (diff) | |
download | php-git-be87834321151d908d9dc879e8d3e462fc67b733.tar.gz |
- Merged fix for bug #51958 socket_accept() fails on IPv6 server sockets.
See r309238 for commit in trunk.
Diffstat (limited to 'ext/sockets')
-rw-r--r-- | ext/sockets/sockets.c | 23 | ||||
-rw-r--r-- | ext/sockets/tests/bug51958.phpt | 22 |
2 files changed, 33 insertions, 12 deletions
diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 7d836862d6..7b3c54ff88 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -394,16 +394,13 @@ static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSR } /* }}} */ -static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la TSRMLS_DC) /* {{{ */ +static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la, socklen_t *la_len TSRMLS_DC) /* {{{ */ { - socklen_t salen; php_socket *out_sock = (php_socket*)emalloc(sizeof(php_socket)); *new_sock = out_sock; - salen = sizeof(*la); - out_sock->blocking = 1; - out_sock->bsd_socket = accept(in_sock->bsd_socket, la, &salen); + out_sock->bsd_socket = accept(in_sock->bsd_socket, la, la_len); if (IS_INVALID_SOCKET(out_sock)) { PHP_SOCKET_ERROR(out_sock, "unable to accept incoming connection", errno); @@ -411,6 +408,10 @@ static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct return 0; } + out_sock->error = 0; + out_sock->blocking = 1; + out_sock->type = la->sa_family; + return 1; } /* }}} */ @@ -880,9 +881,10 @@ PHP_FUNCTION(socket_create_listen) Accepts a connection on the listening socket fd */ PHP_FUNCTION(socket_accept) { - zval *arg1; - php_socket *php_sock, *new_sock; - struct sockaddr_in sa; + zval *arg1; + php_socket *php_sock, *new_sock; + php_sockaddr_storage sa; + socklen_t sa_len = sizeof(sa); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { return; @@ -890,13 +892,10 @@ PHP_FUNCTION(socket_accept) ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); - if (!php_accept_connect(php_sock, &new_sock, (struct sockaddr *) &sa TSRMLS_CC)) { + if (!php_accept_connect(php_sock, &new_sock, (struct sockaddr*)&sa, &sa_len TSRMLS_CC)) { RETURN_FALSE; } - new_sock->error = 0; - new_sock->blocking = 1; - ZEND_REGISTER_RESOURCE(return_value, new_sock, le_socket); } /* }}} */ diff --git a/ext/sockets/tests/bug51958.phpt b/ext/sockets/tests/bug51958.phpt new file mode 100644 index 0000000000..e5db68340c --- /dev/null +++ b/ext/sockets/tests/bug51958.phpt @@ -0,0 +1,22 @@ +--TEST--
+Bug #51958: socket_accept() fails on IPv6 server sockets
+--SKIPIF--
+<?php
+if (!extension_loaded('sockets')) {
+ die('skip sockets extension not available.');
+}
+if (!defined('IPPROTO_IPV6')) {
+ die('skip IPv6 not available.');
+}
+if (PHP_OS != "WINNT")
+ die('skip test relies Winsock's error code for WSAEWOULDBLOCK/EAGAIN');
+--FILE--
+<?php
+$listenfd = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);
+socket_bind($listenfd, "::1", 13579);
+socket_listen($listenfd);
+socket_set_nonblock($listenfd);
+$connfd = @socket_accept($listenfd);
+echo socket_last_error();
+--EXPECT--
+10035
|