Stylistic changes: Don't use a macro for the malloc'ed length since it
[openssl.git] / apps / passwd.c
index 06155979f444a4b1d837bacc07ccf39a534f365c..4650ea503dde68e347ad08dc34403de6d1217c9b 100644 (file)
@@ -20,7 +20,7 @@
 # include <openssl/des.h>
 #endif
 #ifndef NO_APR1
-# include <openssl/des.h>
+# include <openssl/md5.h>
 #endif
 
 
@@ -54,6 +54,8 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
  * -reverse      - switch table columns
  */
 
+int MAIN(int, char **);
+
 int MAIN(int argc, char **argv)
        {
        int ret = 1;
@@ -61,6 +63,7 @@ int MAIN(int argc, char **argv)
        int in_stdin = 0;
        char *salt = NULL, *passwd = NULL, **passwds = NULL;
        char *salt_malloc = NULL, *passwd_malloc = NULL;
+       size_t passwd_malloc_size = 0;
        int pw_source_defined = 0;
        BIO *in = NULL, *out = NULL;
        int i, badopt, opt_done;
@@ -194,7 +197,10 @@ int MAIN(int argc, char **argv)
        if (passwds == NULL)
                {
                /* no passwords on the command line */
-               passwd = passwd_malloc = Malloc(pw_maxlen + 1);
+
+               passwd_malloc_size = pw_maxlen + 2;
+               /* longer than necessary so that we can warn about truncation */
+               passwd = passwd_malloc = Malloc(passwd_malloc_size);
                if (passwd_malloc == NULL)
                        goto err;
                }
@@ -206,7 +212,7 @@ int MAIN(int argc, char **argv)
                
                passwds = passwds_static;
                if (in == NULL)
-                       if (EVP_read_pw_string(passwd_malloc, pw_maxlen + 1, "Password: ", 0) != 0)
+                       if (EVP_read_pw_string(passwd_malloc, passwd_malloc_size, "Password: ", 0) != 0)
                                goto err;
                passwds[0] = passwd_malloc;
                }
@@ -324,12 +330,12 @@ static char *apr1_crypt(const char *passwd, const char *salt)
 
                MD5_Init(&md2);
                MD5_Update(&md2, (i & 1) ? (unsigned char *) passwd : buf,
-                                (i & 1) ?               passwd_len : sizeof buf);
+                                (i & 1) ? passwd_len : sizeof buf);
                if (i % 3)
                        MD5_Update(&md2, salt_out, salt_len);
                if (i % 7)
                        MD5_Update(&md2, passwd, passwd_len);
-               MD5_Update(&md2, (i & 1) ?        buf : (unsigned char *) passwd,
+               MD5_Update(&md2, (i & 1) ? buf : (unsigned char *) passwd,
                                 (i & 1) ? sizeof buf : passwd_len);
                MD5_Final(buf, &md2);
                }
@@ -346,7 +352,9 @@ static char *apr1_crypt(const char *passwd, const char *salt)
                        buf_perm[dest] = buf[source];
                buf_perm[14] = buf[5];
                buf_perm[15] = buf[11];
+#ifndef PEDANTIC /* Unfortunately, this generates a "no effect" warning */
                assert(16 == sizeof buf_perm);
+#endif
                
                output = salt_out + salt_len;
                assert(output == out_buf + strlen(out_buf));