mirror of https://github.com/mirror/busybox.git
cryptpw: do not segfault on EOF. Closes 6350
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>1_22_stable
parent
16614e9bab
commit
1bf560e9c3
|
@ -92,6 +92,7 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
char salt[MAX_PW_SALT_LEN];
|
char salt[MAX_PW_SALT_LEN];
|
||||||
char *salt_ptr;
|
char *salt_ptr;
|
||||||
|
char *password;
|
||||||
const char *opt_m, *opt_S;
|
const char *opt_m, *opt_S;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
@ -123,15 +124,19 @@ int cryptpw_main(int argc UNUSED_PARAM, char **argv)
|
||||||
|
|
||||||
xmove_fd(fd, STDIN_FILENO);
|
xmove_fd(fd, STDIN_FILENO);
|
||||||
|
|
||||||
puts(pw_encrypt(
|
password = argv[0];
|
||||||
argv[0] ? argv[0] : (
|
if (!password) {
|
||||||
/* Only mkpasswd, and only from tty, prompts.
|
/* Only mkpasswd, and only from tty, prompts.
|
||||||
* Otherwise it is a plain read. */
|
* Otherwise it is a plain read. */
|
||||||
(isatty(STDIN_FILENO) && applet_name[0] == 'm')
|
password = (isatty(STDIN_FILENO) && applet_name[0] == 'm')
|
||||||
? bb_ask_stdin("Password: ")
|
? bb_ask_stdin("Password: ")
|
||||||
: xmalloc_fgetline(stdin)
|
: xmalloc_fgetline(stdin)
|
||||||
),
|
;
|
||||||
salt, 1));
|
/* may still be NULL on EOF/error */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (password)
|
||||||
|
puts(pw_encrypt(password, salt, 1));
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue