fix s_client crash
[openssl.git] / apps / passwd.c
index 3c6fd5204e22afdf74fba18ce229aba587326343..8dd85428706514b4110dcfbc6919c999175bf75c 100644 (file)
@@ -221,12 +221,9 @@ int passwd_main(int argc, char **argv)
         /* no passwords on the command line */
 
         passwd_malloc_size = pw_maxlen + 2;
-        /*
-         * longer than necessary so that we can warn about truncation
-         */
-        passwd = passwd_malloc = OPENSSL_malloc(passwd_malloc_size);
-        if (passwd_malloc == NULL)
-            goto end;
+        /* longer than necessary so that we can warn about truncation */
+        passwd = passwd_malloc =
+            app_malloc(passwd_malloc_size, "password buffer");
     }
 
     if ((in == NULL) && (passwds == NULL)) {
@@ -287,10 +284,8 @@ int passwd_main(int argc, char **argv)
 
  end:
     ERR_print_errors(bio_err);
-    if (salt_malloc)
-        OPENSSL_free(salt_malloc);
-    if (passwd_malloc)
-        OPENSSL_free(passwd_malloc);
+    OPENSSL_free(salt_malloc);
+    OPENSSL_free(passwd_malloc);
     BIO_free(in);
     return (ret);
 }
@@ -426,9 +421,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
 # ifndef OPENSSL_NO_DES
         if (usecrypt) {
             if (*salt_malloc_p == NULL) {
-                *salt_p = *salt_malloc_p = OPENSSL_malloc(3);
-                if (*salt_malloc_p == NULL)
-                    goto end;
+                *salt_p = *salt_malloc_p = app_malloc(3, "salt buffer");
             }
             if (RAND_bytes((unsigned char *)*salt_p, 2) <= 0)
                 goto end;
@@ -447,9 +440,7 @@ static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
             int i;
 
             if (*salt_malloc_p == NULL) {
-                *salt_p = *salt_malloc_p = OPENSSL_malloc(9);
-                if (*salt_malloc_p == NULL)
-                    goto end;
+                *salt_p = *salt_malloc_p = app_malloc(9, "salt buffer");
             }
             if (RAND_bytes((unsigned char *)*salt_p, 8) <= 0)
                 goto end;