Skip to content

Commit f4b31ed

Browse files
authored
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.
1 parent 690fe07 commit f4b31ed

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In :mod:`ssl`, system call failures that OpenSSL reports using
2+
``ERR_LIB_SYS`` are now raised as :exc:`OSError`.

Modules/_ssl.c

+10
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@ PySSL_SetError(PySSLSocket *sslsock, const char *filename, int lineno)
667667
ERR_GET_REASON(e) == SSL_R_CERTIFICATE_VERIFY_FAILED) {
668668
type = state->PySSLCertVerificationErrorObject;
669669
}
670+
if (ERR_GET_LIB(e) == ERR_LIB_SYS) {
671+
// A system error is being reported; reason is set to errno
672+
errno = ERR_GET_REASON(e);
673+
return PyErr_SetFromErrno(PyExc_OSError);
674+
}
670675
p = PY_SSL_ERROR_SYSCALL;
671676
}
672677
break;
@@ -692,6 +697,11 @@ PySSL_SetError(PySSLSocket *sslsock, const char *filename, int lineno)
692697
errstr = "EOF occurred in violation of protocol";
693698
}
694699
#endif
700+
if (ERR_GET_LIB(e) == ERR_LIB_SYS) {
701+
// A system error is being reported; reason is set to errno
702+
errno = ERR_GET_REASON(e);
703+
return PyErr_SetFromErrno(PyExc_OSError);
704+
}
695705
break;
696706
}
697707
default:

0 commit comments

Comments
 (0)