diff options
| author | Antonio Gutierrez <chibby0ne@gmail.com> | 2019-10-08 06:22:17 +0200 |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2019-10-07 21:22:17 -0700 |
| commit | 0d3fe8ae4961bf551e7d5e42559e2ede1a08fd7c (patch) | |
| tree | 8ddcbaae6fdebf3694b166b58995aa849b812f3d /Lib/crypt.py | |
| parent | 4d5f94b8cd20f804c7868c5395a15aa6032f874c (diff) | |
| download | cpython-git-0d3fe8ae4961bf551e7d5e42559e2ede1a08fd7c.tar.gz | |
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>
Diffstat (limited to 'Lib/crypt.py')
| -rw-r--r-- | Lib/crypt.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/crypt.py b/Lib/crypt.py index 8846602d76..33dbc46bb3 100644 --- a/Lib/crypt.py +++ b/Lib/crypt.py @@ -10,6 +10,7 @@ except ModuleNotFoundError: else: raise ImportError("The required _crypt module was not built as part of CPython") +import errno import string as _string from random import SystemRandom as _SystemRandom from collections import namedtuple as _namedtuple @@ -88,7 +89,14 @@ def _add_method(name, *args, rounds=None): method = _Method(name, *args) globals()['METHOD_' + name] = method salt = mksalt(method, rounds=rounds) - result = crypt('', salt) + result = None + try: + 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: methods.append(method) return True |
