diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c index 66b37eb79ea..bca3bd1363e 100644 --- a/ext/standard/crypt.c +++ b/ext/standard/crypt.c @@ -204,6 +204,14 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch salt[1] == '2' && salt[3] == '$') { char output[PHP_MAX_SALT_LEN + 1]; + int k = 7; + + while (isalnum(salt[k]) || '.' == salt[k] || '/' == salt[k]) { + k++; + } + if (k != salt_len) { + return NULL; + } memset(output, 0, PHP_MAX_SALT_LEN + 1); diff --git a/ext/standard/tests/strings/bug72703.phpt b/ext/standard/tests/strings/bug72703.phpt new file mode 100644 index 00000000000..5e3bf4875d9 --- /dev/null +++ b/ext/standard/tests/strings/bug72703.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #72703 Out of bounds global memory read in BF_crypt triggered by password_verify +--SKIPIF-- + +--FILE-- + +==OK== +--EXPECT-- +bool(false) +==OK== +