11 comments

  • NewJazz 2 hours ago ago

    musl’s crypt() returns the string * as an error indicator when the key is over 256 bytes long. * is also exactly what the stored field contains for every account with no password, so the “hash” matches and the login succeeds.

    Does anyone know why musl does this? Are they the only C library that behaves this way?

    For a C library that famously tries to adhere to POSIX as much as possible, this seems like a crazy choice. From POSIX standard:

    Upon successful completion, crypt() shall return a pointer to the encoded string. The first two bytes of the returned value shall be those of the salt argument. Otherwise, it shall return a null pointer and set errno to indicate the error.

    https://pubs.opengroup.org/onlinepubs/9699919799/functions/c...

    • hnfong an hour ago ago

      There's a very detailed trace of how the bug was developed over decades at sshhole.com and the relevant discussion in https://news.ycombinator.com/item?id=50378228

      • NewJazz an hour ago ago

        Thanks yeah just woke up, finished making my way through the single-article website and still unclear if other libcs do the same thing (the article says libxcrypt picked it up, but only after musl did it).

    • worksonmine an hour ago ago

      Apparently because some devs didn't check for NULL which resulted in crashes. Weird choice to fix other peoples' bad programming by deviating from the spec.

      • cyphar 33 minutes ago ago

        To be fair (as the sshole site mentions) it is also necessary to fake a password hash check to avoid timing side channels revealing to remote clients whether users exist, so returning a sentinel value is not a horrifically unreasonable solution to make sure even naive code does approximately the right thing.

        Though I am surprised that all of the code examples do not use constant-time strcmp(). Actually, I wonder if even constant-time strncmp() would still leak information about whether the account is disabled because in that case both arguments are much shorter? Food for thought.

        But yeah, the crypt(3) API is very 80s C, the man page even features a lengthy description of a long-deprecated and utterly broken hashing algorithm using DES that is even implied to be broken in the text itself (and the warning message is so old it refers to "parallel computers" as though they were a new concept). Given that the default mode is to use a broken hashing algorithm, I'm shocked anyone actually uses the libc crypt(3) -- surely it's trivial to just write your own that isn't awful...?

    • api an hour ago ago

      TBH that sounds like a straight up bug in that it deviates dangerously from the spec.

      • NewJazz 9 minutes ago ago

        Which is notable because musl is more known for adhering to the spec to the point where they break programs that assume nonstandard behavior.

  • undefined 4 minutes ago ago
    [deleted]
  • throwa356262 2 hours ago ago

    Discussion from a few hours ago:

    https://news.ycombinator.com/item?id=50377221

  • slopinthebag 10 minutes ago ago

    i think it's just unbelievable there isn't a bigger push to move away from c to languages that can prevent stuff like this from happening. this and just the pure unsafety. it's 2026. it's like pure negligence at this point, the equivalent of building a bridge with matchsticks because you like using it more.

  • Mantis99 an hour ago ago

    [flagged]