Skip to content

Commit 4dc0b40

Browse files
orlitzkyarnaud-lb
authored andcommitted
ext/standard/crypt.c: handle musl failure tokens
Musl's crypt() returns "*" to indicate failure in contrast with the "*0" returned by PHP/libxcrypt. This causes test failures, but more importantly, is a pretty silly thing to expect the user to know. This commit catches the musl value and turns it into "*0".
1 parent f5d2e7b commit 4dc0b40

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ext/standard/crypt.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,19 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch
177177

178178
if (!crypt_res || (salt[0] == '*' && salt[1] == '0')) {
179179
return NULL;
180-
} else {
180+
}
181+
else if (!strcmp(crypt_res, "*")) {
182+
/* Musl crypt() uses "*" as a failure token rather
183+
* than the "*0" that libxcrypt/PHP use. Our test
184+
* suite in particular looks for "*0" in a few places,
185+
* and it would be annoying to handle both values
186+
* explicitly. It seems wise to abstract this detail
187+
* from the end user: if it's annoying for us, imagine
188+
* how annoying it would be in end-user code; not that
189+
* anyone would think of it. */
190+
return NULL;
191+
}
192+
else {
181193
result = zend_string_init(crypt_res, strlen(crypt_res), 0);
182194
return result;
183195
}

0 commit comments

Comments
 (0)