Skip to content

Commit

Permalink
fixup! store_direct_fetch return stack of return value
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Wernli committed Feb 20, 2024
1 parent a1f187a commit 7a6deb3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ static int load_obj(struct desired_data_type_cbdata *cbdata,
long der_len, OSSL_CALLBACK *object_cb, void *object_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
{
int ret = RET_OSSL_CARRY_ON_DECODING;
P11PROV_PK11_URI *obj = NULL;
char *uri = NULL;

Expand All @@ -109,16 +108,19 @@ static int load_obj(struct desired_data_type_cbdata *cbdata,

p11prov_set_error_mark(ctx->provctx);

ret = p11prov_store_direct_fetch(ctx->provctx, uri,
filter_for_desired_data_type, cbdata,
pw_cb, pw_cbarg);
STACK_OF(int) *fetch_results = p11prov_store_direct_fetch(
ctx->provctx, uri, filter_for_desired_data_type, cbdata, pw_cb,
pw_cbarg);
if (fetch_results) {
sk_int_pop_free(fetch_results, int_free);
}

p11prov_pop_error_to_mark(ctx->provctx);
p11prov_clear_last_error_mark(ctx->provctx);
done:
OPENSSL_free(uri);
P11PROV_PK11_URI_free(obj);
return ret;
return RET_OSSL_CARRY_ON_DECODING;
}

static int p11prov_der_decoder_p11prov_obj_decode(
Expand Down
32 changes: 26 additions & 6 deletions src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,22 +590,42 @@ static int p11prov_store_set_ctx_params(void *pctx, const OSSL_PARAM params[])
return RET_OSSL_OK;
}

int p11prov_store_direct_fetch(void *provctx, const char *uri,
OSSL_CALLBACK *object_cb, void *object_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
void int_free(int *value)
{
OPENSSL_free(value);
}

STACK_OF(int)
*p11prov_store_direct_fetch(void *provctx, const char *uri,
OSSL_CALLBACK *object_cb, void *object_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg)
{
int ret = RET_OSSL_OK;
struct p11prov_store_ctx *ctx = NULL;
ctx = p11prov_store_open(provctx, uri);
if (!ctx) {
return RET_OSSL_ERR;
return NULL;
}

STACK_OF(int) *ret = sk_int_new_null();
if (!ret) {
return NULL;
}

do {
ret &=
int *load_ret_value = OPENSSL_malloc(sizeof(int));
if (!load_ret_value) {
goto done;
}

*load_ret_value =
p11prov_store_load(ctx, object_cb, object_cbarg, pw_cb, pw_cbarg);

if (sk_int_push(ret, load_ret_value) <= 0) {
goto done;
};
} while (!p11prov_store_eof(ctx));

done:
p11prov_store_ctx_free(ctx);
return ret;
}
Expand Down
11 changes: 8 additions & 3 deletions src/store.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define _STORE_H

#include <openssl/core.h>
#include <openssl/safestack.h>

#define DISPATCH_STORE_FN(name) DECL_DISPATCH_FUNC(store, p11prov_store, name)
#define DISPATCH_STORE_ELEM(NAME, name) \
Expand All @@ -13,8 +14,12 @@
}
extern const OSSL_DISPATCH p11prov_store_functions[];

int p11prov_store_direct_fetch(void *provctx, const char *uri,
OSSL_CALLBACK *object_cb, void *object_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg);
DEFINE_STACK_OF(int);
void int_free(int *value);

STACK_OF(int)
*p11prov_store_direct_fetch(void *provctx, const char *uri,
OSSL_CALLBACK *object_cb, void *object_cbarg,
OSSL_PASSPHRASE_CALLBACK *pw_cb, void *pw_cbarg);

#endif /* _STORE_H */

0 comments on commit 7a6deb3

Please sign in to comment.