summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-01-06 12:57:27 +0100
committerDr. David von Oheimb <dev@ddvo.net>2021-01-20 15:59:22 +0100
commit03f4e3ded67ed4eacf0849f05c73222a56d4f8ef (patch)
tree08b8ace67a51d27697c8f130473386b74c3cbad4 /apps
parent2367238ced66d5da07e104aa9d8ab1e1eae64ec4 (diff)
apps.c: Clean up copy_extensions()
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/13711)
Diffstat (limited to 'apps')
-rw-r--r--apps/lib/apps.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/apps/lib/apps.c b/apps/lib/apps.c
index d5654d9dc9..6a8ee415f9 100644
--- a/apps/lib/apps.c
+++ b/apps/lib/apps.c
@@ -968,26 +968,29 @@ int set_ext_copy(int *copy_type, const char *arg)
int copy_extensions(X509 *x, X509_REQ *req, int copy_type)
{
- STACK_OF(X509_EXTENSION) *exts = NULL;
- X509_EXTENSION *ext, *tmpext;
- ASN1_OBJECT *obj;
- int i, idx, ret = 0;
- if (!x || !req || (copy_type == EXT_COPY_NONE))
+ STACK_OF(X509_EXTENSION) *exts;
+ int i, ret = 0;
+
+ if (x == NULL || req == NULL)
+ return 0;
+ if (copy_type == EXT_COPY_NONE)
return 1;
exts = X509_REQ_get_extensions(req);
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
- ext = sk_X509_EXTENSION_value(exts, i);
- obj = X509_EXTENSION_get_object(ext);
- idx = X509_get_ext_by_OBJ(x, obj, -1);
- /* Does extension exist? */
+ X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
+ ASN1_OBJECT *obj = X509_EXTENSION_get_object(ext);
+ int idx = X509_get_ext_by_OBJ(x, obj, -1);
+
+ /* Does extension exist in target? */
if (idx != -1) {
/* If normal copy don't override existing extension */
if (copy_type == EXT_COPY_ADD)
continue;
/* Delete all extensions of same type */
do {
- tmpext = X509_get_ext(x, idx);
+ X509_EXTENSION *tmpext = X509_get_ext(x, idx);
+
X509_delete_ext(x, idx);
X509_EXTENSION_free(tmpext);
idx = X509_get_ext_by_OBJ(x, obj, -1);
@@ -996,13 +999,10 @@ int copy_extensions(X509 *x, X509_REQ *req, int copy_type)
if (!X509_add_ext(x, ext, -1))
goto end;
}
-
ret = 1;
end:
-
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
-
return ret;
}