diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-06-30 21:28:55 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-06-30 21:28:55 +0200 |
commit | 1bf560e9c374b073757509b334eb099c59f64191 (patch) | |
tree | e3fbe6f88c130e856e37344488ee8807700f512e | |
parent | 16614e9babf6b920587597f35c5b2122ac815e16 (diff) | |
download | busybox-w32-1bf560e9c374b073757509b334eb099c59f64191.tar.gz busybox-w32-1bf560e9c374b073757509b334eb099c59f64191.tar.bz2 busybox-w32-1bf560e9c374b073757509b334eb099c59f64191.zip |
cryptpw: do not segfault on EOF. Closes 6350
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | loginutils/cryptpw.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/loginutils/cryptpw.c b/loginutils/cryptpw.c index a36f920f4..29f0fbe91 100644 --- a/loginutils/cryptpw.c +++ b/loginutils/cryptpw.c | |||
@@ -92,6 +92,7 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv) | |||
92 | { | 92 | { |
93 | char salt[MAX_PW_SALT_LEN]; | 93 | char salt[MAX_PW_SALT_LEN]; |
94 | char *salt_ptr; | 94 | char *salt_ptr; |
95 | char *password; | ||
95 | const char *opt_m, *opt_S; | 96 | const char *opt_m, *opt_S; |
96 | int fd; | 97 | int fd; |
97 | 98 | ||
@@ -123,15 +124,19 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv) | |||
123 | 124 | ||
124 | xmove_fd(fd, STDIN_FILENO); | 125 | xmove_fd(fd, STDIN_FILENO); |
125 | 126 | ||
126 | puts(pw_encrypt( | 127 | password = argv[0]; |
127 | argv[0] ? argv[0] : ( | 128 | if (!password) { |
128 | /* Only mkpasswd, and only from tty, prompts. | 129 | /* Only mkpasswd, and only from tty, prompts. |
129 | * Otherwise it is a plain read. */ | 130 | * Otherwise it is a plain read. */ |
130 | (isatty(STDIN_FILENO) && applet_name[0] == 'm') | 131 | password = (isatty(STDIN_FILENO) && applet_name[0] == 'm') |
131 | ? bb_ask_stdin("Password: ") | 132 | ? bb_ask_stdin("Password: ") |
132 | : xmalloc_fgetline(stdin) | 133 | : xmalloc_fgetline(stdin) |
133 | ), | 134 | ; |
134 | salt, 1)); | 135 | /* may still be NULL on EOF/error */ |
136 | } | ||
137 | |||
138 | if (password) | ||
139 | puts(pw_encrypt(password, salt, 1)); | ||
135 | 140 | ||
136 | return EXIT_SUCCESS; | 141 | return EXIT_SUCCESS; |
137 | } | 142 | } |