51
51
/* Used to check DES salts to ensure that they contain only valid characters */
52
52
#define IS_VALID_SALT_CHARACTER (c ) (((c) >= '.' && (c) <= '9') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
53
53
54
- #define DES_INVALID_SALT_ERROR "Supplied salt is not valid for DES. Possible bug in provided salt format."
55
-
56
-
57
54
PHP_MINIT_FUNCTION (crypt ) /* {{{ */
58
55
{
59
56
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
163
160
ZEND_SECURE_ZERO (output , PHP_MAX_SALT_LEN + 1 );
164
161
return result ;
165
162
}
166
- } else {
163
+ } else if (salt [0 ] == '_'
164
+ || (IS_VALID_SALT_CHARACTER (salt [0 ]) && IS_VALID_SALT_CHARACTER (salt [1 ]))) {
167
165
/* 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
-
180
166
memset (& buffer , 0 , sizeof (buffer ));
181
167
_crypt_extended_init_r ();
182
168
@@ -187,17 +173,13 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch
187
173
result = zend_string_init (crypt_res , strlen (crypt_res ), 0 );
188
174
return result ;
189
175
}
176
+ } else {
177
+ /* Unknown hash type */
178
+ return NULL ;
190
179
}
191
180
}
192
181
#else
193
182
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
-
201
183
# if defined(HAVE_CRYPT_R ) && (defined(_REENTRANT ) || defined(_THREAD_SAFE ))
202
184
{
203
185
# if defined(CRYPT_R_STRUCT_CRYPT_DATA )
0 commit comments