Skip to content

Commit 57f32d8

Browse files
vstinnerencukou
authored andcommitted
pythongh-127257: ssl: Raise OSError for ERR_LIB_SYS (pythonGH-127361) (pythonGH-127905) (pythonGH-131971)
pythongh-127257: ssl: Raise OSError for ERR_LIB_SYS (pythonGH-127361) From the ERR_raise manpage: ERR_LIB_SYS This "library code" indicates that a system error is being reported. In this case, the reason code given to `ERR_raise()` and `ERR_raise_data()` *must* be `errno(3)`. This PR only handles ERR_LIB_SYS for the high-lever error types SSL_ERROR_SYSCALL and SSL_ERROR_SSL, i.e., not the ones where OpenSSL indicates it has some more information about the issue. (cherry picked from commit f4b31ed) (cherry picked from commit 7f707fa) Co-authored-by: Petr Viktorin <[email protected]>
1 parent f2f2ce0 commit 57f32d8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Modules/_ssl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ PySSL_SetError(PySSLSocket *obj, int ret, const char *filename, int lineno)
638638
errstr = "Some I/O error occurred";
639639
}
640640
} else {
641+
if (ERR_GET_LIB(e) == ERR_LIB_SYS) {
642+
// A system error is being reported; reason is set to errno
643+
errno = ERR_GET_REASON(e);
644+
return PyErr_SetFromErrno(PyExc_OSError);
645+
}
641646
p = PY_SSL_ERROR_SYSCALL;
642647
}
643648
break;
@@ -648,6 +653,11 @@ PySSL_SetError(PySSLSocket *obj, int ret, const char *filename, int lineno)
648653
if (e == 0)
649654
/* possible? */
650655
errstr = "A failure in the SSL library occurred";
656+
if (ERR_GET_LIB(e) == ERR_LIB_SYS) {
657+
// A system error is being reported; reason is set to errno
658+
errno = ERR_GET_REASON(e);
659+
return PyErr_SetFromErrno(PyExc_OSError);
660+
}
651661
break;
652662
}
653663
default:

0 commit comments

Comments
 (0)