summaryrefslogtreecommitdiff
path: root/loginutils/cryptpw.c
diff options
context:
space:
mode:
authorDenys Vlasenko2013-06-30 21:28:55 +0200
committerDenys Vlasenko2013-06-30 21:28:55 +0200
commit1bf560e9c374b073757509b334eb099c59f64191 (patch)
treee3fbe6f88c130e856e37344488ee8807700f512e /loginutils/cryptpw.c
parent16614e9babf6b920587597f35c5b2122ac815e16 (diff)
downloadbusybox-1bf560e9c374b073757509b334eb099c59f64191.zip
busybox-1bf560e9c374b073757509b334eb099c59f64191.tar.gz
cryptpw: do not segfault on EOF. Closes 6350
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'loginutils/cryptpw.c')
-rw-r--r--loginutils/cryptpw.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c
index a36f920..29f0fbe 100644
--- a/loginutils/cryptpw.c
+++ b/loginutils/cryptpw.c
@@ -92,6 +92,7 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
{
char salt[MAX_PW_SALT_LEN];
char *salt_ptr;
+ char *password;
const char *opt_m, *opt_S;
int fd;
@@ -123,15 +124,19 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
xmove_fd(fd, STDIN_FILENO);
- puts(pw_encrypt(
- argv[0] ? argv[0] : (
- /* Only mkpasswd, and only from tty, prompts.
- * Otherwise it is a plain read. */
- (isatty(STDIN_FILENO) && applet_name[0] == 'm')
+ password = argv[0];
+ if (!password) {
+ /* Only mkpasswd, and only from tty, prompts.
+ * Otherwise it is a plain read. */
+ password = (isatty(STDIN_FILENO) && applet_name[0] == 'm')
? bb_ask_stdin("Password: ")
: xmalloc_fgetline(stdin)
- ),
- salt, 1));
+ ;
+ /* may still be NULL on EOF/error */
+ }
+
+ if (password)
+ puts(pw_encrypt(password, salt, 1));
return EXIT_SUCCESS;
}