Browse Source

Neon commit c0584f37 (Catch ERR_LIB_SYS errors and handle map the returned errno correctly)

Needed for compatibility with OpenSSH 3.4+

https://github.com/notroj/neon/pull/214
https://github.com/notroj/neon/issues/213

Source commit: 297818a98b00154e9110d0f3bb1ffe2842195072
Martin Prikryl 2 weeks ago
parent
commit
1cb9ac3efd
1 changed files with 10 additions and 5 deletions
  1. 10 5
      libs/neon/src/ne_socket.c

+ 10 - 5
libs/neon/src/ne_socket.c

@@ -672,7 +672,7 @@ static int readable_ossl(ne_socket *sock, int secs)
 /* SSL error handling, according to SSL_get_error(3). */
 static int error_ossl(ne_socket *sock, int sret)
 {
-    int errnum = SSL_get_error(sock->ssl, sret);
+    int errnum = SSL_get_error(sock->ssl, sret), reason;
     unsigned long err;
 
     if (errnum == SSL_ERROR_ZERO_RETURN) {
@@ -687,11 +687,12 @@ static int error_ossl(ne_socket *sock, int sret)
     
     /* for all other errors, look at the OpenSSL error stack */
     err = ERR_get_error();
-    NE_DEBUG(NE_DBG_SSL, "ssl: Got OpenSSL error stack %lu\n", err);
-
-    if (ERR_GET_LIB(err) == ERR_LIB_SSL) {
-	int reason = ERR_GET_REASON(err);
+    reason = ERR_GET_REASON(err);
+    NE_DEBUG(NE_DBG_SSL, "ssl: Got OpenSSL error %lu (library=%d, reason=%d)\n",
+             err, ERR_GET_LIB(err), reason);
 
+    switch (ERR_GET_LIB(err)) {
+    case ERR_LIB_SSL:
 #ifdef SSL_R_UNEXPECTED_EOF_WHILE_READING
         /* OpenSSL 3 signals truncation this way. */
 	if (reason == SSL_R_UNEXPECTED_EOF_WHILE_READING) {
@@ -704,6 +705,10 @@ static int error_ossl(ne_socket *sock, int sret)
 	    set_error(sock, _("Secure connection reset"));
 	    return NE_SOCK_RESET;
 	}
+        break;
+    case ERR_LIB_SYS:
+        set_strerror(sock, reason);
+        return MAP_ERR(reason);
     }
 
     if (err == 0) {