Skip to content

Commit d579b10

Browse files
committed
Remove deprecated DES fallback in crypt()
1 parent 8a8c8d4 commit d579b10

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

UPGRADING

+3
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ PHP 8.0 UPGRADE NOTES
437437
respect the inherited locale without an explicit setlocale() call. An
438438
explicit setlocale() call is now always required if you wish to change any
439439
locale component from the default.
440+
. Remove deprecated DES fallback in crypt(). If an unknown salt format is
441+
passed to crypt(), the function will fail with *0 instead of falling back
442+
to a weak DES hash now.
440443

441444
- Sysvmsg:
442445
. msg_get_queue() will now return an SysvMessageQueue object rather than a

ext/standard/crypt.c

+5-23
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
/* Used to check DES salts to ensure that they contain only valid characters */
5252
#define IS_VALID_SALT_CHARACTER(c) (((c) >= '.' && (c) <= '9') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
5353

54-
#define DES_INVALID_SALT_ERROR "Supplied salt is not valid for DES. Possible bug in provided salt format."
55-
56-
5754
PHP_MINIT_FUNCTION(crypt) /* {{{ */
5855
{
5956
REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", PHP_MAX_SALT_LEN, CONST_CS | CONST_PERSISTENT);
@@ -163,20 +160,9 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch
163160
ZEND_SECURE_ZERO(output, PHP_MAX_SALT_LEN + 1);
164161
return result;
165162
}
166-
} else {
163+
} else if (salt[0] == '_'
164+
|| (IS_VALID_SALT_CHARACTER(salt[0]) && IS_VALID_SALT_CHARACTER(salt[1]))) {
167165
/* DES Fallback */
168-
169-
/* Only check the salt if it's not EXT_DES */
170-
if (salt[0] != '_') {
171-
/* DES style hashes */
172-
if (!IS_VALID_SALT_CHARACTER(salt[0]) || !IS_VALID_SALT_CHARACTER(salt[1])) {
173-
if (!quiet) {
174-
/* error consistently about invalid DES fallbacks */
175-
php_error_docref(NULL, E_DEPRECATED, DES_INVALID_SALT_ERROR);
176-
}
177-
}
178-
}
179-
180166
memset(&buffer, 0, sizeof(buffer));
181167
_crypt_extended_init_r();
182168

@@ -187,17 +173,13 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch
187173
result = zend_string_init(crypt_res, strlen(crypt_res), 0);
188174
return result;
189175
}
176+
} else {
177+
/* Unknown hash type */
178+
return NULL;
190179
}
191180
}
192181
#else
193182

194-
if (salt[0] != '$' && salt[0] != '_' && (!IS_VALID_SALT_CHARACTER(salt[0]) || !IS_VALID_SALT_CHARACTER(salt[1]))) {
195-
if (!quiet) {
196-
/* error consistently about invalid DES fallbacks */
197-
php_error_docref(NULL, E_DEPRECATED, DES_INVALID_SALT_ERROR);
198-
}
199-
}
200-
201183
# if defined(HAVE_CRYPT_R) && (defined(_REENTRANT) || defined(_THREAD_SAFE))
202184
{
203185
# if defined(CRYPT_R_STRUCT_CRYPT_DATA)

ext/standard/tests/crypt/des_fallback_invalid_salt.phpt

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ var_dump(crypt("test", "$#"));
77
var_dump(crypt("test", "$5zd$01"));
88

99
?>
10-
--EXPECTF--
11-
Deprecated: crypt(): Supplied salt is not valid for DES. Possible bug in provided salt format. in %s on line %d
12-
string(13) "$#8MWASl5pGIk"
13-
14-
Deprecated: crypt(): Supplied salt is not valid for DES. Possible bug in provided salt format. in %s on line %d
15-
string(13) "$54mkQyGCLvHs"
10+
--EXPECT--
11+
string(2) "*0"
12+
string(2) "*0"

0 commit comments

Comments
 (0)