Browse files

fix bug: HandleSSLError should correctly process zero code: sometime …

…it does not mean an error, but sometimes it does
  • Loading branch information...
1 parent 5e4e87a commit ce1155a1a3f270d317580fb0078186cd8d5244ba @fat-crocodile committed Nov 9, 2012
Showing with 18 additions and 5 deletions.
  1. +17 −4 src/node_crypto.cc
  2. +1 −1 src/node_crypto.h
View
21 src/node_crypto.cc
@@ -890,8 +890,9 @@ int Connection::HandleBIOError(BIO *bio, const char* func, int rv) {
}
-int Connection::HandleSSLError(const char* func, int rv) {
- if (rv >= 0) return rv;
+int Connection::HandleSSLError(const char* func, int rv, bool zeroIsAnError) {
+ if (rv > 0) return rv;
+ if ((rv == 0) && !zeroIsAnError) return rv;
int err = SSL_get_error(ssl_, rv);
@@ -1358,7 +1359,7 @@ Handle<Value> Connection::ClearOut(const Arguments& args) {
}
int bytes_read = SSL_read(ss->ssl_, buffer_data + off, len);
- ss->HandleSSLError("SSL_read:ClearOut", bytes_read);
+ ss->HandleSSLError("SSL_read:ClearOut", bytes_read, false);
ss->SetShutdownFlags();
return scope.Close(Integer::New(bytes_read));
@@ -1718,7 +1719,19 @@ Handle<Value> Connection::Shutdown(const Arguments& args) {
if (ss->ssl_ == NULL) return False();
int rv = SSL_shutdown(ss->ssl_);
- ss->HandleSSLError("SSL_shutdown", rv);
+ if (rv == 0) {
+ // from http://openssl.org/docs/ssl/SSL_shutdown.html:
+ //
+ // The shutdown is not yet finished. Call SSL_shutdown() for a second time,
+ // if a bidirectional shutdown shall be performed. The output of SSL_get_error(3)
+ // may be misleading, as an erroneous SSL_ERROR_SYSCALL may be flagged even though
+ // no error occurred.
+ //
+ // Do we need bidirectional shutdown? I guess "yes", but someone more experienced should make decision.
+ rv = SSL_shutdown(ss->ssl_);
+ }
+
+ ss->HandleSSLError("SSL_shutdown", rv, false);
ss->SetShutdownFlags();
return scope.Close(Integer::New(rv));
View
2 src/node_crypto.h
@@ -214,7 +214,7 @@ class Connection : ObjectWrap {
#endif
int HandleBIOError(BIO *bio, const char* func, int rv);
- int HandleSSLError(const char* func, int rv);
+ int HandleSSLError(const char* func, int rv, bool zeroIsAnError = true);
void ClearError();
void SetShutdownFlags();

0 comments on commit ce1155a

Please sign in to comment.