diff options
author | Rich Salz <rsalz@akamai.com> | 2021-02-10 13:33:41 -0500 |
---|---|---|
committer | Pauli <ppzgs1@gmail.com> | 2021-02-12 08:34:17 +1000 |
commit | 22040fb790c854cefb04bed98ed38ea6357daf83 (patch) | |
tree | 988702702f8cfdbb675e0b016996fc4ca98d9fb5 /apps/lib/app_rand.c | |
parent | 03bbd346f4410c329d472cc043fb6c49f6688eba (diff) |
Allow -rand to be repeated
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14135)
Diffstat (limited to 'apps/lib/app_rand.c')
-rw-r--r-- | apps/lib/app_rand.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/apps/lib/app_rand.c b/apps/lib/app_rand.c index b1c092752e..913e66e73f 100644 --- a/apps/lib/app_rand.c +++ b/apps/lib/app_rand.c @@ -14,7 +14,7 @@ #include <openssl/conf.h> static char *save_rand_file; -static char *files_to_load; +static STACK_OF(OPENSSL_STRING) *randfiles; void app_RAND_load_conf(CONF *c, const char *section) { @@ -32,35 +32,46 @@ void app_RAND_load_conf(CONF *c, const char *section) save_rand_file = OPENSSL_strdup(randfile); } -int app_RAND_load(void) +static int loadfiles(char *name) { - char *p, *save; + char *p; int last, ret = 1; - if (files_to_load == NULL) - return 1; - - save = files_to_load; for ( ; ; ) { last = 0; - for (p = files_to_load; *p != '\0' && *p != LIST_SEPARATOR_CHAR; p++) + for (p = name; *p != '\0' && *p != LIST_SEPARATOR_CHAR; p++) continue; if (*p == '\0') last = 1; *p = '\0'; - if (RAND_load_file(files_to_load, -1) < 0) { - BIO_printf(bio_err, "Can't load %s into RNG\n", files_to_load); + if (RAND_load_file(name, -1) < 0) { + BIO_printf(bio_err, "Can't load %s into RNG\n", name); ERR_print_errors(bio_err); ret = 0; } if (last) break; - files_to_load = p + 1; - if (*files_to_load == '\0') + name = p + 1; + if (*name == '\0') break; } - files_to_load = NULL; - OPENSSL_free(save); + return ret; +} + +int app_RAND_load(void) +{ + char *p; + int i, ret = 1; + + if (randfiles == NULL) + return 1; + + for (i = 0; i < sk_OPENSSL_STRING_num(randfiles); i++) { + p = sk_OPENSSL_STRING_value(randfiles, i); + if (!loadfiles(p)) + ret = 0; + } + sk_OPENSSL_STRING_free(randfiles); return ret; } @@ -89,7 +100,11 @@ int opt_rand(int opt) case OPT_R__LAST: break; case OPT_R_RAND: - files_to_load = opt_arg(); + if (randfiles == NULL + && (randfiles = sk_OPENSSL_STRING_new_null()) == NULL) + return 0; + if (!sk_OPENSSL_STRING_push(randfiles, opt_arg())) + return 0; break; case OPT_R_WRITERAND: OPENSSL_free(save_rand_file); |