Skip to content

Fix a few external crypt() issues on musl #16702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2024
Merged

Conversation

orlitzky
Copy link
Contributor

@orlitzky orlitzky commented Nov 5, 2024

Using --with-external-libcrypt on a musl system (even if libxcrypt is installed) will use the crypt() implementation from musl. There are a few incompatibilities to work around before the test suite will pass on a such a system.

Among other things, this test tries to run too few and too many rounds
of SHA256. In both cases, it is expecting an error, but that behavior
depends on the implementation:

  * PHP's own implementation raises an error in either case
  * libxcrypt raises an error in either case
  * Older versions of glibc would clamp the number of rounds
    to a valid amount (newer versions don't have libcrypt)
  * Musl libc clamps values that are too low, but raises an error
    for values that are too high

If PHP is built with --with-external-libcrypt, the musl implementation
above can be used. Even if libxcrypt is installed, PHP will notice
that no additional -lfoo flags are needed to use the crypt
implementation in musl. To pass on such a system, we must not test
for the "too few rounds" behavior.
Musl's crypt() implementation of DES tries to handle invalid salts and
can make this test fail because it returns an answer and not an
error. Even musl however will reject a salt with a ':' in it, so we
can make this test cross-platform by supplying an even less valid
salt.
@orlitzky
Copy link
Contributor Author

orlitzky commented Nov 5, 2024

@arnaud-lb may be interested in this :)

@@ -215,6 +215,17 @@ PHP_FUNCTION(crypt)
RETURN_STRING("*0");
}
}
else if (zend_string_equals_literal(result, "*")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in the php_crypt function itself.

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".
@arnaud-lb arnaud-lb merged commit 4dc0b40 into php:master Nov 7, 2024
10 checks passed
arnaud-lb added a commit that referenced this pull request Nov 7, 2024
@arnaud-lb
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants