Skip to content

Commit

Permalink
Fix error handling duplicating STORED_ALGORITHMS
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcaswell committed May 8, 2024
1 parent 7c06fc5 commit 1a3fa62
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions crypto/property/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,6 @@ static void impl_free(IMPLEMENTATION *impl)
}
}

/* Shallow dup of an ALGORITHM */
static void alg_shallow_dup(uintmax_t idx, ALGORITHM *alg, void *arg)
{
SPARSE_ARRAY_OF(ALGORITHM) **saalg = arg;

if (*saalg == NULL)
return;

if (!ossl_sa_ALGORITHM_set(*saalg, idx, alg)) {
ossl_sa_ALGORITHM_free(*saalg);
*saalg = NULL;
}
return;
}

static STORED_ALGORITHMS *stored_algs_new(void)
{
STORED_ALGORITHMS *ret;
Expand All @@ -227,32 +212,58 @@ static STORED_ALGORITHMS *stored_algs_new(void)
return ret;
}

/* Does not free the actual ALGORITHM structures */
static void stored_algs_free(STORED_ALGORITHMS *algs)
{
if (algs == NULL)
return;

ossl_sa_ALGORITHM_free(algs->algs);
OPENSSL_free(algs);
}

struct data_shallow_dup {
int err;
SPARSE_ARRAY_OF(ALGORITHM) *saalg;
};

/* Shallow dup of an ALGORITHM */
static void alg_shallow_dup(uintmax_t idx, ALGORITHM *alg, void *arg)
{
struct data_shallow_dup *data = arg;

if (data->err)
return;

if (!ossl_sa_ALGORITHM_set(data->saalg, idx, alg))
data->err = 1;

return;
}

static STORED_ALGORITHMS *
stored_algs_shallow_dup(STORED_ALGORITHMS *src)
{
STORED_ALGORITHMS *dest;
struct data_shallow_dup data;

dest = stored_algs_new();
if (dest == NULL)
return NULL;
dest->cache_need_flush = src->cache_need_flush;
dest->cache_nelem = src->cache_nelem;

ossl_sa_ALGORITHM_doall_arg(src->algs, alg_shallow_dup, &dest->algs);
data.err = 0;
data.saalg = dest->algs;
ossl_sa_ALGORITHM_doall_arg(src->algs, alg_shallow_dup, &data);
if (data.err) {
stored_algs_free(dest);
return NULL;
}

return dest;
}

/* Does not free the actual ALGORITHM structures */
static void stored_algs_free(STORED_ALGORITHMS *algs)
{
if (algs == NULL)
return;

ossl_sa_ALGORITHM_free(algs->algs);
OPENSSL_free(algs);
}

static void impl_cache_free(QUERY *elem)
{
if (elem != NULL) {
Expand Down

0 comments on commit 1a3fa62

Please sign in to comment.