From c4c1993af63fe4c0d19d44ebbd38996471c141af Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Sat, 18 Jun 2016 21:29:47 -0700 Subject: Fixed bug #72439 (Stream socket with remote address leads to a segmentation fault) --- main/streams/xp_socket.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'main/streams/xp_socket.c') diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 995e90f98d..90c5df0b8a 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -247,16 +247,27 @@ static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t bu struct sockaddr **addr, socklen_t *addrlen TSRMLS_DC) { - php_sockaddr_storage sa; - socklen_t sl = sizeof(sa); int ret; int want_addr = textaddr || addr; if (want_addr) { + php_sockaddr_storage sa; + socklen_t sl = sizeof(sa); ret = recvfrom(sock->socket, buf, buflen, flags, (struct sockaddr*)&sa, &sl); ret = (ret == SOCK_CONN_ERR) ? -1 : ret; - php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, - textaddr, textaddrlen, addr, addrlen TSRMLS_CC); + if (sl) { + php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, + textaddr, textaddrlen, addr, addrlen TSRMLS_CC); + } else { + if (textaddr) { + *textaddr = estrndup("", 0); + *textaddrlen = 0; + } + if (addr) { + *addr = NULL; + *addrlen = 0; + } + } } else { ret = recv(sock->socket, buf, buflen, flags); ret = (ret == SOCK_CONN_ERR) ? -1 : ret; @@ -303,7 +314,7 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void ret = recv(sock->socket, &buf, sizeof(buf), MSG_PEEK); err = php_socket_errno(); if (0 == ret || /* the counterpart did properly shutdown*/ - 0 > ret && err != EWOULDBLOCK && err != EAGAIN) { /* there was an unrecoverable error */ + (0 > ret && err != EWOULDBLOCK && err != EAGAIN)) { /* there was an unrecoverable error */ alive = 0; } } -- cgit v1.2.1