Error out on NUL bytes.

This commit is contained in:
Alex Gaynor 2015-03-13 21:28:16 -04:00
parent fc72ac30d6
commit ea678c1dd1
2 changed files with 7 additions and 0 deletions

View File

@ -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))

View File

@ -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))