diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-03-13 21:28:16 -0400 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-03-13 21:28:16 -0400 |
| commit | ea678c1dd1260495cb9ac51caebd4d884ea3098b (patch) | |
| tree | a3cccc6a2fa446615b24dfeda8b008dd71dc1c14 | |
| parent | fc72ac30d6887bdad08a6d103507d929f9e9bd85 (diff) | |
| download | py-bcrypt-git-ea678c1dd1260495cb9ac51caebd4d884ea3098b.tar.gz | |
Error out on NUL bytes.
| -rw-r--r-- | bcrypt/__init__.py | 3 | ||||
| -rw-r--r-- | tests/test_bcrypt.py | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/bcrypt/__init__.py b/bcrypt/__init__.py index 0ecafba..29a4701 100644 --- a/bcrypt/__init__.py +++ b/bcrypt/__init__.py @@ -138,6 +138,9 @@ def hashpw(password, salt): if isinstance(password, six.text_type) or isinstance(salt, six.text_type): raise TypeError("Unicode-objects must be encoded before hashing") + if b"\x00" in password: + raise ValueError("password may not contain NUL bytes") + hashed = _ffi.new("unsigned char[]", 128) retval = _bcrypt_lib.crypt_rn(password, salt, hashed, len(hashed)) diff --git a/tests/test_bcrypt.py b/tests/test_bcrypt.py index e6329a6..c735dc4 100644 --- a/tests/test_bcrypt.py +++ b/tests/test_bcrypt.py @@ -264,3 +264,7 @@ def test_hashpw_str_salt(): b"password", six.text_type("$2a$04$cVWp4XaNU8a4v1uMRum2SO"), ) + +def test_nul_byte(): + with pytest.raises(ValueError): + bcrypt.hashpw(b"abc\0def", bcrypt.gensalt(0)) |
