From 8bfd900be58e259625cd1af6779fe80e9e91331c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 7 Jan 2015 00:26:00 +0900 Subject: [PATCH] src, examples: Check return value --- examples/client.c | 10 +++++++--- src/HttpServer.cc | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/client.c b/examples/client.c index 1fdbcdd6..1927e05a 100644 --- a/examples/client.c +++ b/examples/client.c @@ -152,7 +152,7 @@ static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data, connection->want_io = IO_NONE; ERR_clear_error(); rv = SSL_write(connection->ssl, data, (int)length); - if (rv < 0) { + if (rv <= 0) { int err = SSL_get_error(connection->ssl, rv); if (err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_READ) { connection->want_io = @@ -529,8 +529,12 @@ static void fetch_uri(const struct URI *uri) { connection.want_io = IO_NONE; /* Send connection header in blocking I/O mode */ - SSL_write(ssl, NGHTTP2_CLIENT_CONNECTION_PREFACE, - NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); + rv = SSL_write(ssl, NGHTTP2_CLIENT_CONNECTION_PREFACE, + NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); + if (rv <= 0) { + dief("SSL_write failed: could not send connection preface", + ERR_error_string(ERR_get_error(), NULL)); + } /* Here make file descriptor non-block */ make_non_block(fd); diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 8072905b..ca211c54 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -1470,7 +1470,7 @@ int start_listen(struct ev_loop *loop, Sessions *sessions, close(fd); continue; } - util::make_socket_nonblocking(fd); + (void)util::make_socket_nonblocking(fd); #ifdef IPV6_V6ONLY if (rp->ai_family == AF_INET6) { if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, @@ -1547,7 +1547,10 @@ int HttpServer::run() { SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY); SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS); - SSL_CTX_set_cipher_list(ssl_ctx, ssl::DEFAULT_CIPHER_LIST); + if (SSL_CTX_set_cipher_list(ssl_ctx, ssl::DEFAULT_CIPHER_LIST) == 0) { + std::cerr << ERR_error_string(ERR_get_error(), nullptr) << std::endl; + return -1; + } const unsigned char sid_ctx[] = "nghttpd"; SSL_CTX_set_session_id_context(ssl_ctx, sid_ctx, sizeof(sid_ctx) - 1);