]> jfr.im git - solanum.git/blobdiff - tools/mkpasswd.c
Merge pull request #334 from edk0/massnotice
[solanum.git] / tools / mkpasswd.c
index 689f912efdb2ddd1d37e5a97fcb62a31edbe0edb..8b8c96c186f6adb2fa2a67fb021c38d08418c904 100644 (file)
@@ -41,8 +41,8 @@ static char *make_bf_salt_para(int, char *);
 static char *generate_random_salt(char *, int);
 static char *generate_poor_salt(char *, int);
 
-static void full_usage(void);
-static void brief_usage(void);
+static void full_usage(void) __attribute__((noreturn));
+static void brief_usage(void) __attribute__((noreturn));
 
 static char saltChars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        /* 0 .. 63, ascii - 64 */
@@ -90,7 +90,7 @@ main(int argc, char *argv[])
        int c;
        char *saltpara = NULL;
        char *salt;
-       char *hashed;
+       char *hashed, *hashed2;
        int flag = 0;
        int length = 0;         /* Not Set */
        int rounds = 0;         /* Not set, since blowfish needs 4 by default, a side effect
@@ -194,10 +194,24 @@ main(int argc, char *argv[])
        }
        else
        {
-               hashed = strdup(rb_crypt(getpass("plaintext: "), salt));
+               plaintext = getpass("plaintext: ");
+               hashed = rb_crypt(plaintext, salt);
+               if (!hashed)
+               {
+                       fprintf(stderr, "rb_crypt() failed\n");
+                       return 1;
+               }
+               hashed = strdup(hashed);
+
                plaintext = getpass("again: ");
+               hashed2 = rb_crypt(plaintext, salt);
+               if (!hashed2)
+               {
+                       fprintf(stderr, "rb_crypt() failed\n");
+                       return 1;
+               }
 
-               if (strcmp(rb_crypt(plaintext, salt), hashed) != 0)
+               if (strcmp(hashed, hashed2) != 0)
                {
                        fprintf(stderr, "Passwords do not match\n");
                        return 1;