X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=apps%2Frand.c;h=33dbf57d9c16959d670ce0a4b1042054b8ba9a87;hb=d49e23ec589e32e70f485fac379417097a831897;hp=89a23a293a93c5ee7f0d746af8f73a7a6cba25c7;hpb=846e33c729311169d9c988ceba29484b3783f244;p=openssl.git diff --git a/apps/rand.c b/apps/rand.c index 89a23a293a..33dbf57d9c 100644 --- a/apps/rand.c +++ b/apps/rand.c @@ -22,7 +22,7 @@ typedef enum OPTION_choice { OPT_OUT, OPT_ENGINE, OPT_RAND, OPT_BASE64, OPT_HEX } OPTION_CHOICE; -OPTIONS rand_options[] = { +const OPTIONS rand_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [flags] num\n"}, {OPT_HELP_STR, 1, '-', "Valid options are:\n"}, {"help", OPT_HELP, '-', "Display this summary"}, @@ -39,6 +39,7 @@ OPTIONS rand_options[] = { int rand_main(int argc, char **argv) { + ENGINE *e = NULL; BIO *out = NULL; char *inrand = NULL, *outfile = NULL, *prog; OPTION_CHOICE o; @@ -60,7 +61,7 @@ int rand_main(int argc, char **argv) outfile = opt_arg(); break; case OPT_ENGINE: - (void)setup_engine(opt_arg(), 0); + e = setup_engine(opt_arg(), 0); break; case OPT_RAND: inrand = opt_arg(); @@ -105,22 +106,27 @@ int rand_main(int argc, char **argv) r = RAND_bytes(buf, chunk); if (r <= 0) goto end; - if (format != FORMAT_TEXT) /* hex */ - BIO_write(out, buf, chunk); - else { + if (format != FORMAT_TEXT) { + if (BIO_write(out, buf, chunk) != chunk) + goto end; + } else { for (i = 0; i < chunk; i++) - BIO_printf(out, "%02x", buf[i]); + if (BIO_printf(out, "%02x", buf[i]) != 2) + goto end; } num -= chunk; } if (format == FORMAT_TEXT) BIO_puts(out, "\n"); - (void)BIO_flush(out); + if (BIO_flush(out) <= 0 || !app_RAND_write_file(NULL)) + goto end; - app_RAND_write_file(NULL); ret = 0; end: + if (ret != 0) + ERR_print_errors(bio_err); + release_engine(e); BIO_free_all(out); return (ret); }