libbb: don't die if crypt() returns NULL
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 9 Feb 2014 13:38:03 +0000 (14:38 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 9 Feb 2014 13:38:03 +0000 (14:38 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/pw_encrypt.c

index 39ffa084f29a81ce2817e15a9547a0e9d3fb74a8..bfc7030a8387f81daa44ce8f1ccc6f50e3380233 100644 (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