ports/security/py-M2Crypto/patches/patch-src_M2Crypto_BIO_py

57 lines
1.8 KiB
Text
Raw Normal View History

2023-08-16 22:26:55 +00:00
Partially revert https://gitlab.com/m2crypto/m2crypto/commit/738cd0bf3dc2ee619f598290d5bf4c2190987f16:
* Fix BIO.File ... return type of BIO.readline() and close properly.
That is, flush BIO.File() before closing and close also underlying
system file.
For Python 2 this results in:
python2 -c "import M2Crypto; M2Crypto.BIO.openfile('/etc/ssl/cert.pem')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/M2Crypto/BIO.py", line 284, in openfile
return File(f)
File "/usr/local/lib/python2.7/site-packages/M2Crypto/BIO.py", line 239, in __init__
pyfile.flush()
IOError: [Errno 9] Bad file descriptor
https://gitlab.com/m2crypto/m2crypto/issues/211
Index: src/M2Crypto/BIO.py
--- src/M2Crypto/BIO.py.orig
+++ src/M2Crypto/BIO.py
@@ -235,8 +235,9 @@ class File(BIO):
#
# https://docs.python.org/3.3/c-api/file.html
#
- pyfile.flush()
- self.fname = pyfile.name
+ if six.PY3:
+ pyfile.flush()
+ self.fname = pyfile.name
self.pyfile = pyfile
# Be wary of https://github.com/openssl/openssl/pull/1925
# BIO_new_fd is NEVER to be used before OpenSSL 1.1.1
@@ -246,7 +247,8 @@ class File(BIO):
self.bio = m2.bio_new_pyfile(pyfile, m2.bio_noclose)
self.close_pyfile = close_pyfile
- self.closed = False
+ if six.PY3:
+ self.closed = False
def flush(self):
# type: () -> None
@@ -255,8 +257,9 @@ class File(BIO):
def close(self):
# type: () -> None
- self.flush()
- super(File, self).close()
+ if six.PY3:
+ self.flush()
+ super(File, self).close()
if self.close_pyfile:
self.pyfile.close()