From ecc4290d3dba768aa5abb224afdfc5955224c0a5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 8 Jan 2014 02:15:46 +0900 Subject: [PATCH] nghttp: Fix crash on plain HTTP --- src/nghttp.cc | 54 ++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/nghttp.cc b/src/nghttp.cc index 7c736bd7..ce73a3cc 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -1313,36 +1313,38 @@ void eventcb(bufferevent *bev, short events, void *ptr) if(client->need_upgrade()) { rv = client->on_upgrade_connect(); } else { - // Check NPN or ALPN result - const unsigned char *next_proto = nullptr; - unsigned int next_proto_len; - SSL_get0_next_proto_negotiated(client->ssl, - &next_proto, &next_proto_len); - for(int i = 0; i < 2; ++i) { - if(next_proto) { - if(config.verbose) { - std::cout << "The negotiated protocol: "; - std::cout.write(reinterpret_cast(next_proto), - next_proto_len); - std::cout << std::endl; + if(client->ssl) { + // Check NPN or ALPN result + const unsigned char *next_proto = nullptr; + unsigned int next_proto_len; + SSL_get0_next_proto_negotiated(client->ssl, + &next_proto, &next_proto_len); + for(int i = 0; i < 2; ++i) { + if(next_proto) { + if(config.verbose) { + std::cout << "The negotiated protocol: "; + std::cout.write(reinterpret_cast(next_proto), + next_proto_len); + std::cout << std::endl; + } + if(NGHTTP2_PROTO_VERSION_ID_LEN != next_proto_len || + memcmp(NGHTTP2_PROTO_VERSION_ID, next_proto, + NGHTTP2_PROTO_VERSION_ID_LEN) != 0) { + next_proto = nullptr; + } + break; } - if(NGHTTP2_PROTO_VERSION_ID_LEN != next_proto_len || - memcmp(NGHTTP2_PROTO_VERSION_ID, next_proto, - NGHTTP2_PROTO_VERSION_ID_LEN) != 0) { - next_proto = nullptr; - } - break; - } #if OPENSSL_VERSION_NUMBER >= 0x10002000L - SSL_get0_alpn_selected(client->ssl, &next_proto, &next_proto_len); + SSL_get0_alpn_selected(client->ssl, &next_proto, &next_proto_len); #else // OPENSSL_VERSION_NUMBER < 0x10002000L - break; + break; #endif // OPENSSL_VERSION_NUMBER < 0x10002000L - } - if(!next_proto) { - print_protocol_nego_error(); - client->disconnect(); - return; + } + if(!next_proto) { + print_protocol_nego_error(); + client->disconnect(); + return; + } } rv = client->on_connect(); }