提交 750d5587 编写于 作者: A Andy Polyakov

apps/req.c: fix -addext option.

Address even Coverity nit.
Reviewed-by: NPaul Dale <paul.dale@oracle.com>
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6671)
上级 5d58e8f1
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <openssl/objects.h> #include <openssl/objects.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/bn.h>
#include <openssl/lhash.h> #include <openssl/lhash.h>
#ifndef OPENSSL_NO_RSA #ifndef OPENSSL_NO_RSA
# include <openssl/rsa.h> # include <openssl/rsa.h>
...@@ -177,21 +176,22 @@ static void exts_cleanup(OPENSSL_STRING *x) ...@@ -177,21 +176,22 @@ static void exts_cleanup(OPENSSL_STRING *x)
static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv) static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
{ {
char *p; char *p;
size_t off;
/* Check syntax. */ /* Check syntax. */
if (strchr(kv, '=') == NULL)
return 1;
/* Skip leading whitespace, make a copy. */ /* Skip leading whitespace, make a copy. */
while (*kv && isspace(*kv)) while (*kv && isspace(*kv))
if (*++kv == '\0') if (*++kv == '\0')
return 1; return 1;
if ((p = strchr(kv, '=')) == NULL)
return 1;
off = p - kv;
if ((kv = OPENSSL_strdup(kv)) == NULL) if ((kv = OPENSSL_strdup(kv)) == NULL)
return -1; return -1;
/* Skip trailing space before the equal sign. */ /* Skip trailing space before the equal sign. */
for (p = strchr(kv, '='); p > kv; --p) for (p = kv + off; p > kv; --p)
if (p[-1] != ' ' && p[-1] != '\t') if (!isspace(p[-1]))
break; break;
if (p == kv) { if (p == kv) {
OPENSSL_free(kv); OPENSSL_free(kv);
...@@ -199,16 +199,13 @@ static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv) ...@@ -199,16 +199,13 @@ static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
} }
*p = '\0'; *p = '\0';
/* Finally have a clean "key"; see if it's there. */ /* Finally have a clean "key"; see if it's there [by attempt to add it]. */
if (lh_OPENSSL_STRING_retrieve(addexts, (OPENSSL_STRING*)kv) != NULL) { if ((p = (char *)lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING*)kv))
BIO_printf(bio_err, "Extension \"%s\" repeated\n", kv); != NULL || lh_OPENSSL_STRING_error(addexts)) {
OPENSSL_free(kv); OPENSSL_free(p != NULL ? p : kv);
return 1; return -1;
} }
/* Not found; add it. */
if (lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING*)kv) == NULL)
return -1;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册