Skip to content

Avoid triggering SIGPIPE after stream_socket_shutdown(SHUT_WR) of a SSL stream #2605

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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ext/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,16 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
/* fall through */
break;
}
break;

case STREAM_XPORT_OP_SHUTDOWN:
if (sslsock->ssl_active && (xparam->how == STREAM_SHUT_WR || xparam->how == STREAM_SHUT_RDWR)) {
if (SSL_shutdown(sslsock->ssl_handle) == -1) {
php_stream_socket_ops.set_option(stream, option, value, ptrparam); /* ensure socket shutdown either way, but report failure */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually going to work for non-blocking socket? The thing is that if it is -1 then in case of the non-blocking socket the operation is not completed and it will have to be finished once the data can be read or written. It basically depends on SSL_get_error result. So closing socket might not be a good idea maybe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should just add a new stream_socket_shutdown_crypto function?

return PHP_STREAM_OPTION_RETURN_ERR;
}
}
break;
}

return php_stream_socket_ops.set_option(stream, option, value, ptrparam);
Expand Down