BIO *out = NULL;
char *outfile = NULL, *prog;
OPTION_CHOICE o;
- int format = FORMAT_BINARY, i, num = -1, r, ret = 1;
+ int format = FORMAT_BINARY, r, i, ret = 1, buflen = 131072;
+ long num = -1;
+ uint8_t *buf = NULL;
prog = opt_init(argc, argv, rand_options);
while ((o = opt_next()) != OPT_EOF) {
argc = opt_num_rest();
argv = opt_rest();
if (argc == 1) {
- if (!opt_int(argv[0], &num) || num <= 0)
+ if (!opt_long(argv[0], &num) || num <= 0)
goto opthelp;
} else if (!opt_check_rest_arg(NULL)) {
goto opthelp;
out = BIO_push(b64, out);
}
+ buf = app_malloc(buflen, "buffer for output file");
while (num > 0) {
- unsigned char buf[4096];
- int chunk;
+ long chunk;
- chunk = num;
- if (chunk > (int)sizeof(buf))
- chunk = sizeof(buf);
+ chunk = (num > buflen) ? buflen : num;
r = RAND_bytes(buf, chunk);
if (r <= 0)
goto end;
end:
if (ret != 0)
ERR_print_errors(bio_err);
+ OPENSSL_free(buf);
release_engine(e);
BIO_free_all(out);
return ret;