Skip to content
This repository was archived by the owner on Jun 24, 2021. It is now read-only.

Commit 6002cce

Browse files
committedDec 20, 2016
mkpasswd: avoid strdup(NULL) and the like if rb_crypt() fails
1 parent d1f8acb commit 6002cce

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed
 

‎tools/mkpasswd.c

+17-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ main(int argc, char *argv[])
9090
int c;
9191
char *saltpara = NULL;
9292
char *salt;
93-
char *hashed;
93+
char *hashed, *hashed2;
9494
int flag = 0;
9595
int length = 0; /* Not Set */
9696
int rounds = 0; /* Not set, since blowfish needs 4 by default, a side effect
@@ -194,10 +194,24 @@ main(int argc, char *argv[])
194194
}
195195
else
196196
{
197-
hashed = strdup(rb_crypt(getpass("plaintext: "), salt));
197+
plaintext = getpass("plaintext: ");
198+
hashed = rb_crypt(plaintext, salt);
199+
if (!hashed)
200+
{
201+
fprintf(stderr, "rb_crypt() failed\n");
202+
return 1;
203+
}
204+
hashed = strdup(hashed);
205+
198206
plaintext = getpass("again: ");
207+
hashed2 = rb_crypt(plaintext, salt);
208+
if (!hashed2)
209+
{
210+
fprintf(stderr, "rb_crypt() failed\n");
211+
return 1;
212+
}
199213

200-
if (strcmp(rb_crypt(plaintext, salt), hashed) != 0)
214+
if (strcmp(hashed, hashed2) != 0)
201215
{
202216
fprintf(stderr, "Passwords do not match\n");
203217
return 1;

0 commit comments

Comments
 (0)