apps/req.c: properly report parse errors by duplicated(); simplify the function
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> (Merged from https://github.com/openssl/openssl/pull/19271)
This commit is contained in:
parent
7e0013d973
commit
66fc90f18c
25
apps/req.c
25
apps/req.c
@ -187,8 +187,8 @@ static void exts_cleanup(OPENSSL_STRING *x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is the |kv| key already duplicated? This is remarkably tricky to get right.
|
* Is the |kv| key already duplicated?
|
||||||
* Return 0 if unique, -1 on runtime error; 1 if found or a syntax error.
|
* Return 0 if unique, -1 on runtime error, -2 on syntax error; 1 if found.
|
||||||
*/
|
*/
|
||||||
static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
|
static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
|
||||||
{
|
{
|
||||||
@ -197,11 +197,12 @@ static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
|
|||||||
|
|
||||||
/* Check syntax. */
|
/* Check syntax. */
|
||||||
/* Skip leading whitespace, make a copy. */
|
/* Skip leading whitespace, make a copy. */
|
||||||
while (*kv && isspace(*kv))
|
while (isspace(*kv))
|
||||||
if (*++kv == '\0')
|
kv++;
|
||||||
return 1;
|
if ((p = strchr(kv, '=')) == NULL) {
|
||||||
if ((p = strchr(kv, '=')) == NULL)
|
BIO_printf(bio_err, "Parse error on -addext: missing '='\n");
|
||||||
return 1;
|
return -2;
|
||||||
|
}
|
||||||
off = p - kv;
|
off = p - kv;
|
||||||
if ((kv = OPENSSL_strdup(kv)) == NULL)
|
if ((kv = OPENSSL_strdup(kv)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -211,14 +212,16 @@ static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
|
|||||||
if (!isspace(p[-1]))
|
if (!isspace(p[-1]))
|
||||||
break;
|
break;
|
||||||
if (p == kv) {
|
if (p == kv) {
|
||||||
|
BIO_printf(bio_err, "Parse error on -addext: missing key\n");
|
||||||
OPENSSL_free(kv);
|
OPENSSL_free(kv);
|
||||||
return 1;
|
return -2;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
/* Finally have a clean "key"; see if it's there [by attempt to add it]. */
|
/* Finally have a clean "key"; see if it's there [by attempt to add it]. */
|
||||||
p = (char *)lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING *)kv);
|
p = (char *)lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING *)kv);
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
|
BIO_printf(bio_err, "Duplicate extension name: %s\n", kv);
|
||||||
OPENSSL_free(p);
|
OPENSSL_free(p);
|
||||||
return 1;
|
return 1;
|
||||||
} else if (lh_OPENSSL_STRING_error(addexts)) {
|
} else if (lh_OPENSSL_STRING_error(addexts)) {
|
||||||
@ -456,10 +459,10 @@ int req_main(int argc, char **argv)
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
i = duplicated(addexts, p);
|
i = duplicated(addexts, p);
|
||||||
if (i == 1) {
|
if (i == 1)
|
||||||
BIO_printf(bio_err, "Duplicate extension name: %s\n", p);
|
|
||||||
goto opthelp;
|
goto opthelp;
|
||||||
}
|
if (i == -1)
|
||||||
|
BIO_printf(bio_err, "Internal error handling -addext %s\n", p);
|
||||||
if (i < 0 || BIO_printf(addext_bio, "%s\n", p) < 0)
|
if (i < 0 || BIO_printf(addext_bio, "%s\n", p) < 0)
|
||||||
goto end;
|
goto end;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user