News for hackers. Stuff that matters.
Re:Sshole by gf000 on Thursday November 05, 2026 @02:20PM (#50383209)
You are looking at it from the wrong direction.

The problem is not that you can write bad stuff in rust, the problem is that this particular usage pattern can't be sanely coded in C. This is a public API that should inform users and enforce certain properties. A Results type does exactly that, you would have to go way out of your way to force invalid stuff through that type alone.

Re:Sshole by creata on Thursday November 05, 2026 @02:35PM (#50383391)
I don't think so. In both Rust and C, the solution is the same - make the function explicitly fallible, instead of trying to preserve backward compatibility. In C, the function would probably just look like this, returning zero on success and negative on failure:

    int crypt2(const char *phrase, const char *setting, char *out);
You can call such a signature "insane" if you want, and that's fine, but it would have averted the bug that is the topic of discussion.
Re:Sshole by markasoftware on Thursday November 05, 2026 @03:41PM (#50384209)
what you are suggesting is a form of type safety. There are still degrees of type safety even in C, and this bug resulted from deciding that backwards compatibility is more important than type safety, which I think we agree on.
Re:Sshole by lokar on Thursday November 05, 2026 @04:12PM (#50384515)
And C has effectively deprecated bad APIs over the years. Just not this one.
Re:Sshole by quotemstr on Thursday November 05, 2026 @04:45PM (#50384891)
It's a perfectly sane signature, especially coupled with an API surface that uses the return channel for errors generally.
Re:Sshole by kazinator on Friday November 06, 2026 @06:57PM (#50400175)
[delayed]
Re:Sshole by cowlevel on Friday November 06, 2026 @12:07AM (#50388446)
This isn't good either. Crypt is a pure computation that can't fail for arbitrary reasons. The former implementation could fail if the salt was invalid, which is something you could guarantee. Now it also fails if the password is invalid. That's new behaviour and no matter which way you wrap it up it has the potential to be incompatible. They should have added the maximum length recommendation to the man page, and let DoS attacks continue until the calling software was updated, not the crypt library.