Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do a prelimary check for numbers in openssl prime command. #18092

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions apps/prime.c
Expand Up @@ -19,6 +19,23 @@ typedef enum OPTION_choice {
OPT_PROV_ENUM
} OPTION_CHOICE;

static int check_num(const char *s, const int is_hex)
{
int i;
/*
* It would make sense to use ossl_isxdigit and ossl_isdigit here,
* but ossl_ctype_check is a local symbol in libcrypto.so.
*/
if (is_hex) {
for (i = 0; ('0' <= s[i] && s[i] <= '9')
|| ('A' <= s[i] && s[i] <= 'F')
|| ('a' <= s[i] && s[i] <= 'f'); i++);
} else {
for (i = 0; '0' <= s[i] && s[i] <= '9'; i++);
}
return s[i] == 0;
}

const OPTIONS prime_options[] = {
{OPT_HELP_STR, 1, '-', "Usage: %s [options] [number...]\n"},

Expand Down Expand Up @@ -117,12 +134,10 @@ int prime_main(int argc, char **argv)
OPENSSL_free(s);
} else {
for ( ; *argv; argv++) {
int r;
int r = check_num(argv[0], hex);

if (hex)
r = BN_hex2bn(&bn, argv[0]);
else
r = BN_dec2bn(&bn, argv[0]);
if (r)
r = hex ? BN_hex2bn(&bn, argv[0]) : BN_dec2bn(&bn, argv[0]);

if (!r) {
BIO_printf(bio_err, "Failed to process value (%s)\n", argv[0]);
Expand Down