Skip to content

Commit 7e8276c

Browse files
author
Anthony Ferrara
committed
Fixed bug #62443 (Crypt SHA256/512 Segfaults With Malformed Salt)
Fixed a memory allocation bug in crypt() SHA256/512 that can cause segmentation faults when passed in salts with a null byte early.
1 parent 9743246 commit 7e8276c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414
Stas)
1515
. Fixed bug #62432 (ReflectionMethod random corrupt memory on high
1616
concurrent). (Johannes)
17+
. Fixed bug #62443 (Crypt SHA256/512 Segfaults With Malformed
18+
Salt). (Anthony Ferrara)
1719

1820
- Fileinfo:
1921
. Fixed magic file regex support. (Felipe)

ext/standard/crypt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ PHP_FUNCTION(crypt)
199199
char *output;
200200
int needed = (sizeof(sha512_salt_prefix) - 1
201201
+ sizeof(sha512_rounds_prefix) + 9 + 1
202-
+ strlen(salt) + 1 + 43 + 1);
202+
+ PHP_MAX_SALT_LEN + 1 + 43 + 1);
203203
output = emalloc(needed * sizeof(char *));
204204
salt[salt_in_len] = '\0';
205205

@@ -222,7 +222,7 @@ PHP_FUNCTION(crypt)
222222
char *output;
223223
int needed = (sizeof(sha256_salt_prefix) - 1
224224
+ sizeof(sha256_rounds_prefix) + 9 + 1
225-
+ strlen(salt) + 1 + 43 + 1);
225+
+ PHP_MAX_SALT_LEN + 1 + 43 + 1);
226226
output = emalloc(needed * sizeof(char *));
227227
salt[salt_in_len] = '\0';
228228

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Bug #62443 Crypt SHA256/512 Segfaults With Malformed Salt
3+
--FILE--
4+
<?php
5+
crypt("foo", '$5$'.chr(0).'abc');
6+
crypt("foo", '$6$'.chr(0).'abc');
7+
echo "OK!";
8+
--EXPECT--
9+
OK!

0 commit comments

Comments
 (0)