libbb: don't die if crypt() returns NULL

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2014-02-09 14:38:03 +01:00
parent 4e03d41342
commit 8ed9672660

View File

@ -142,7 +142,14 @@ char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
{
return xstrdup(crypt(clear, salt));
char *s;
s = crypt(clear, salt);
/*
* glibc used to return "" on malformed salts (for example, ""),
* but since 2.17 it returns NULL.
*/
return xstrdup(s ? s : "");
}
#endif