From: tb Date: Fri, 5 Nov 2021 07:25:36 +0000 (+0000) Subject: Garbage collect xobj->data.{ptr,pkey} X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0e189bdbd1d93df7591e98bc919ba996a0adcb83;p=openbsd Garbage collect xobj->data.{ptr,pkey} Both these are essentially unused. Remove the last use of data.ptr by initializing and copying the X509_OBJECT using memset() and struct assignment in X509_STORE_CTX_get_subject_by_name() and add a missing error check for X509_OBJECT_up_ref_count() while there. ok beck --- diff --git a/lib/libcrypto/x509/x509_lcl.h b/lib/libcrypto/x509/x509_lcl.h index 804fff48fc3..e1894e55239 100644 --- a/lib/libcrypto/x509/x509_lcl.h +++ b/lib/libcrypto/x509/x509_lcl.h @@ -246,10 +246,8 @@ struct x509_object_st { /* one of the above types */ int type; union { - char *ptr; X509 *x509; X509_CRL *crl; - EVP_PKEY *pkey; } data; } /* X509_OBJECT */; diff --git a/lib/libcrypto/x509/x509_lu.c b/lib/libcrypto/x509/x509_lu.c index d4ea5276628..8290f896577 100644 --- a/lib/libcrypto/x509/x509_lu.c +++ b/lib/libcrypto/x509/x509_lu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_lu.c,v 1.37 2021/11/01 17:20:50 tb Exp $ */ +/* $OpenBSD: x509_lu.c,v 1.38 2021/11/05 07:25:36 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -57,6 +57,7 @@ */ #include +#include #include #include @@ -349,8 +350,7 @@ X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, X509_LOOKUP_TYPE type, if (ctx == NULL) return 0; - stmp.type = 0; - stmp.data.ptr = NULL; + memset(&stmp, 0, sizeof(stmp)); CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); tmp = X509_OBJECT_retrieve_by_subject(ctx->objs, type, name); @@ -368,10 +368,10 @@ X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, X509_LOOKUP_TYPE type, return 0; } - ret->type = tmp->type; - ret->data.ptr = tmp->data.ptr; + if (!X509_OBJECT_up_ref_count(tmp)) + return 0; - X509_OBJECT_up_ref_count(ret); + *ret = *tmp; return 1; }