closes bpo-38402: Check error of primitive crypt/crypt_r. (GH-16599)
Checks also for encryption algorithms methods not supported in different OSs. Signed-off-by: Antonio Gutierrez <chibby0ne@gmail.com>
This commit is contained in:
parent
4d5f94b8cd
commit
0d3fe8ae49
|
@ -10,6 +10,7 @@ except ModuleNotFoundError:
|
||||||
else:
|
else:
|
||||||
raise ImportError("The required _crypt module was not built as part of CPython")
|
raise ImportError("The required _crypt module was not built as part of CPython")
|
||||||
|
|
||||||
|
import errno
|
||||||
import string as _string
|
import string as _string
|
||||||
from random import SystemRandom as _SystemRandom
|
from random import SystemRandom as _SystemRandom
|
||||||
from collections import namedtuple as _namedtuple
|
from collections import namedtuple as _namedtuple
|
||||||
|
@ -88,7 +89,14 @@ def _add_method(name, *args, rounds=None):
|
||||||
method = _Method(name, *args)
|
method = _Method(name, *args)
|
||||||
globals()['METHOD_' + name] = method
|
globals()['METHOD_' + name] = method
|
||||||
salt = mksalt(method, rounds=rounds)
|
salt = mksalt(method, rounds=rounds)
|
||||||
|
result = None
|
||||||
|
try:
|
||||||
result = crypt('', salt)
|
result = crypt('', salt)
|
||||||
|
except OSError as e:
|
||||||
|
# Not all libc libraries support all encryption methods.
|
||||||
|
if e.errno == errno.EINVAL:
|
||||||
|
return False
|
||||||
|
raise
|
||||||
if result and len(result) == method.total_size:
|
if result and len(result) == method.total_size:
|
||||||
methods.append(method)
|
methods.append(method)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Check the error from the system's underlying ``crypt`` or ``crypt_r``.
|
|
@ -42,6 +42,9 @@ crypt_crypt_impl(PyObject *module, const char *word, const char *salt)
|
||||||
#else
|
#else
|
||||||
crypt_result = crypt(word, salt);
|
crypt_result = crypt(word, salt);
|
||||||
#endif
|
#endif
|
||||||
|
if (crypt_result == NULL) {
|
||||||
|
return PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
}
|
||||||
return Py_BuildValue("s", crypt_result);
|
return Py_BuildValue("s", crypt_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue