diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-11 12:25:59 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-11 12:25:59 +0200 |
commit | d2fe2ba08dd84cd7e94d1ae3e2e9c12ca2b4d561 (patch) | |
tree | a7daa0a4c9c16e38465598c2c9b039061c65cd60 /loginutils/chpasswd.c | |
parent | 7b46d11582047d0dd21b547ff4a913defe646d40 (diff) | |
download | busybox-w32-d2fe2ba08dd84cd7e94d1ae3e2e9c12ca2b4d561.tar.gz busybox-w32-d2fe2ba08dd84cd7e94d1ae3e2e9c12ca2b4d561.tar.bz2 busybox-w32-d2fe2ba08dd84cd7e94d1ae3e2e9c12ca2b4d561.zip |
chpasswd: fix possible free() or non-allocated string. +8 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'loginutils/chpasswd.c')
-rw-r--r-- | loginutils/chpasswd.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/loginutils/chpasswd.c b/loginutils/chpasswd.c index 2262b792a..b7df57e5d 100644 --- a/loginutils/chpasswd.c +++ b/loginutils/chpasswd.c | |||
@@ -33,9 +33,8 @@ static const char chpasswd_longopts[] ALIGN1 = | |||
33 | int chpasswd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 33 | int chpasswd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
34 | int chpasswd_main(int argc UNUSED_PARAM, char **argv) | 34 | int chpasswd_main(int argc UNUSED_PARAM, char **argv) |
35 | { | 35 | { |
36 | char *name, *pass; | 36 | char *name; |
37 | char salt[sizeof("$N$XXXXXXXX")]; | 37 | int opt; |
38 | int opt, rc; | ||
39 | 38 | ||
40 | if (getuid() != 0) | 39 | if (getuid() != 0) |
41 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); | 40 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
@@ -45,6 +44,10 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
45 | opt = getopt32(argv, "em"); | 44 | opt = getopt32(argv, "em"); |
46 | 45 | ||
47 | while ((name = xmalloc_fgetline(stdin)) != NULL) { | 46 | while ((name = xmalloc_fgetline(stdin)) != NULL) { |
47 | char *free_me; | ||
48 | char *pass; | ||
49 | int rc; | ||
50 | |||
48 | pass = strchr(name, ':'); | 51 | pass = strchr(name, ':'); |
49 | if (!pass) | 52 | if (!pass) |
50 | bb_error_msg_and_die("missing new password"); | 53 | bb_error_msg_and_die("missing new password"); |
@@ -52,7 +55,10 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
52 | 55 | ||
53 | xuname2uid(name); /* dies if there is no such user */ | 56 | xuname2uid(name); /* dies if there is no such user */ |
54 | 57 | ||
58 | free_me = NULL; | ||
55 | if (!(opt & OPT_ENC)) { | 59 | if (!(opt & OPT_ENC)) { |
60 | char salt[sizeof("$N$XXXXXXXX")]; | ||
61 | |||
56 | crypt_make_salt(salt, 1); | 62 | crypt_make_salt(salt, 1); |
57 | if (opt & OPT_MD5) { | 63 | if (opt & OPT_MD5) { |
58 | salt[0] = '$'; | 64 | salt[0] = '$'; |
@@ -60,7 +66,7 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
60 | salt[2] = '$'; | 66 | salt[2] = '$'; |
61 | crypt_make_salt(salt + 3, 4); | 67 | crypt_make_salt(salt + 3, 4); |
62 | } | 68 | } |
63 | pass = pw_encrypt(pass, salt, 0); | 69 | free_me = pass = pw_encrypt(pass, salt, 0); |
64 | } | 70 | } |
65 | 71 | ||
66 | /* This is rather complex: if user is not found in /etc/shadow, | 72 | /* This is rather complex: if user is not found in /etc/shadow, |
@@ -81,8 +87,7 @@ int chpasswd_main(int argc UNUSED_PARAM, char **argv) | |||
81 | bb_info_msg("Password for '%s' changed", name); | 87 | bb_info_msg("Password for '%s' changed", name); |
82 | logmode = LOGMODE_STDIO; | 88 | logmode = LOGMODE_STDIO; |
83 | free(name); | 89 | free(name); |
84 | if (!(opt & OPT_ENC)) | 90 | free(free_me); |
85 | free(pass); | ||
86 | } | 91 | } |
87 | return EXIT_SUCCESS; | 92 | return EXIT_SUCCESS; |
88 | } | 93 | } |