diff --git a/src/decoder.c b/src/decoder.c index 3d238636..2ffe27c8 100644 --- a/src/decoder.c +++ b/src/decoder.c @@ -88,9 +88,9 @@ 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; + int ret = RET_OSSL_CARRY_ON_DECODING; obj = d2i_P11PROV_PK11_URI(NULL, &der, der_len); if (!obj) { @@ -109,9 +109,15 @@ 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) { + ret = RET_OSSL_STOP_DECODING; + } else { + sk_int_pop_free(fetch_results, int_free); + ret = RET_OSSL_CARRY_ON_DECODING; + } p11prov_pop_error_to_mark(ctx->provctx); p11prov_clear_last_error_mark(ctx->provctx); diff --git a/src/store.c b/src/store.c index 904f46ff..0f3b77f3 100644 --- a/src/store.c +++ b/src/store.c @@ -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; } diff --git a/src/store.h b/src/store.h index 4cce30cf..fe627b8b 100644 --- a/src/store.h +++ b/src/store.h @@ -5,6 +5,7 @@ #define _STORE_H #include +#include #define DISPATCH_STORE_FN(name) DECL_DISPATCH_FUNC(store, p11prov_store, name) #define DISPATCH_STORE_ELEM(NAME, name) \ @@ -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 */