aboutsummaryrefslogtreecommitdiff
path: root/libbb/pw_encrypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/pw_encrypt.c')
-rw-r--r--libbb/pw_encrypt.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 47c20690f..a60c33c35 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -120,6 +120,7 @@ static char *my_crypt(const char *key, const char *salt)
120 if (!des_cctx) 120 if (!des_cctx)
121 des_cctx = const_des_init(); 121 des_cctx = const_des_init();
122 des_ctx = des_init(des_ctx, des_cctx); 122 des_ctx = des_init(des_ctx, des_cctx);
123 /* Can return NULL if salt is bad ("" or "<one_char>") */
123 return des_crypt(des_ctx, xzalloc(DES_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt); 124 return des_crypt(des_ctx, xzalloc(DES_OUT_BUFSIZE), (unsigned char*)key, (unsigned char*)salt);
124} 125}
125 126
@@ -137,6 +138,8 @@ char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
137 char *encrypted; 138 char *encrypted;
138 139
139 encrypted = my_crypt(clear, salt); 140 encrypted = my_crypt(clear, salt);
141 if (!encrypted)
142 bb_simple_error_msg_and_die("bad salt");
140 143
141 if (cleanup) 144 if (cleanup)
142 my_crypt_cleanup(); 145 my_crypt_cleanup();
@@ -148,14 +151,16 @@ char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
148 151
149char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup) 152char* FAST_FUNC pw_encrypt(const char *clear, const char *salt, int cleanup)
150{ 153{
151 char *s; 154 char *encrypted;
152 155
153 s = crypt(clear, salt); 156 encrypted = crypt(clear, salt);
154 /* 157 /*
155 * glibc used to return "" on malformed salts (for example, ""), 158 * glibc used to return "" on malformed salts (for example, ""),
156 * but since 2.17 it returns NULL. 159 * but since 2.17 it returns NULL.
157 */ 160 */
158 return xstrdup(s ? s : ""); 161 if (!encrypted || !encrypted[0])
162 bb_simple_error_msg_and_die("bad salt");
163 return xstrdup(encrypted);
159} 164}
160 165
161#endif 166#endif