Skip to content

Commit da3b899

Browse files
author
Sascha Schumann
committed
mhash_keygen_s2k() overwrote the limits of a statically allocated buffer
for long salts. We truncate the salt now appropiately. PR: php#11817
1 parent 1b0356e commit da3b899

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ext/mhash/mhash.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,17 @@ PHP_FUNCTION(mhash_keygen_s2k)
225225
password = Z_STRVAL_PP(input_password);
226226
password_len = Z_STRLEN_PP(input_password);
227227

228-
salt_len = Z_STRLEN_PP(input_salt);
228+
salt_len = MIN(Z_STRLEN_PP(input_salt), SALT_SIZE);
229229

230230
if (salt_len > mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED)) {
231231
sprintf( error, "The specified salt [%d] is more bytes than the required by the algorithm [%d]\n", salt_len, mhash_get_keygen_salt_size(KEYGEN_S2K_SALTED));
232232

233233
php_error(E_WARNING, error);
234234
}
235235

236-
memset( salt, 0, SALT_SIZE);
237-
memcpy( salt, Z_STRVAL_PP(input_salt), salt_len);
236+
memcpy(salt, Z_STRVAL_PP(input_salt), salt_len);
237+
if (salt_len < SALT_SIZE)
238+
memset(salt + salt_len, 0, SALT_SIZE - salt_len);
238239
salt_len=SALT_SIZE;
239240

240241
/* if (salt_len==0) {

0 commit comments

Comments
 (0)