Comment by slopinthebag

2 days 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.

How would using a language different than C help here? At it's core this bug is a logic bug, where "*" == crypt(x), because crypt in musl started returning "*" in some cases some years ago. This could be Rust. This could be Go.

Not every C vuln is a memory safety problem.

  • Another comment said that returning a * was to avoid returning null which would crash users of the library who didn't check for null. That seems like a C smell to me

    • Not really. This is like if the char* were an Option<String> but you had programs which stupidly didn't check if the Option had something and assumed it always did. As others have said, Rust would not prevent this.

      17 replies →

  • >because crypt in musl started returning "*" in some cases some years ago

    In Rust, the type of the return value would be a `Result<T, E>`, which means the chain of events that led to this would never have started in the first place.

    • In C the return value would be NULL, except it was changed by musl at some point.

      Edit: at the beginning, crypt always returned a value. So hypothetical Rust return type would be a String, and then it would be retained for backward compatibility. Or something else would happen, this is a complex logic bug triggered by a 25 year old chain of events.

      4 replies →

  • > How would using a language different than C help here?

    Easier to formulate invariants and check/prove them. Better language correlates with safer software.

  • I write firmware where the program has to run for years unattended.

    You are right, C with manual memory management, no lifetime management, lack of phat pointers and a culture of leet has problems with deranged maddening bugs that other languages don't have.

    But this bug first shows how inband signaling is bad news usually. But worse it's a failure to adhere to the spec properly. If you implement a library and you don't adhere to the spec you're going to bone someone.

    Perhaps even worse is obviously the spec doesn't come with any standard testing framework. That was also the root of Apples infamous goto bug.

  • why does this logic bug exist? why are they returning a string, why not a result type, (nil, err), or something else?

    oh right, because c is a crusty old language with barely any features.

Rust would not save you here as this is a logic bug. Nor would, well, really any other language. I suppose someone might claim that Rust's result type would save you but it really wouldn't: I can easily make the error type a String or pretty much any other type with little consequence.

  • Rust would absolutely have saved you here. Even with `Result<String, String>`, which is pretty poor design, there's no confusing `Ok(s)` with `Err(s)`. Sure you can go out of your way to write something like

        let hash = match result {
            OK(s) => s,
            Err(s) => s,
        };
    

    but at that point I feel like the library is forgiven (except for the poor error design).

    @my-huge-pony does make a good point elsewhere in the thread: if the potential error was not foreseen and the code was written originally to return `String` instead of `Result<String, Error>` then even Rust would be in a pickle.

  • languages with more features would mean developers aren't choosing between unchecked NULLs or sentinel strings.

musl's crypt function could be written in Rust, Python, or JavaScript, and still return * when the key is too long.

What exactly do you mean "push"? What do you think is going to make musl developers switch languages?

  • it's unbelievable to me that there isn't a larger movement of developers to move away from c towards better & safer languages. look at how much pushback the rust4linux folks get, primarily from c developers who are simply afraid of change. imagine engineers not adopting safer building practices because "they prefer the old way"....it's disgusting honestly.

    what will it take to move away from c? older devs retiring. Planck said that "science advances one funeral at a time" and i fear it will be the same for software.

    • Moving away from C in any POSIX system is in fact stop being POSIX system as POSIX and linux being unix like system is built on standard that is defined as C library specification.

      Rewriting it to Rust is fine attempt, just hard to call it is unix/posix anymore. It may not matter but semantically true.

    • > what will it take to move away from c? older devs retiring.

      I'll take forking and porting, thank goodness for LLMs.

guess what, this kind of sentinel value mistake could even be made in rust

  • Cars without seatbelts and airbags chopping off driver's heads in relatively slow collisions? Well guess what, that could happen in a modern car as well if the driver sticks their head out the window while going through a very tight tunnel!

    • you followed up an incorrect comparison with another one, are you sure you're a rust programmer?