aboutsummaryrefslogtreecommitdiff
path: root/rpc_api.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2019-04-02 00:58:41 -0400
committerPaul Selkirk <paul@psgd.org>2019-04-02 00:58:41 -0400
commit6b0c67ace3678325443aa21a32b2b10daa018e27 (patch)
tree65d49218a1c57ca67aff2859a4e5a4530b7daeaa /rpc_api.c
parent5e420cb84a401a04557d63a60d30f42699270509 (diff)
Small cleanups in RPC code, e.g. to support null arguments.
- Add support for null pointer arguments in RPCs for get_digest_algorithm_id and get_public_key. This is years overdue, and would have obviated the need for get_public_key_len as a separate RPC. - Refactor pkey_local_get_public_key_len in terms of pkey_local_get_public_key. - Add more parameter sanity checks to rpc_api.c. - Add a len_max parameter to hal_xdr_decode_variable_opaque, rather than having len be an in/out parameter. This brings xdr slightly more in line with the rest of the code base (again after literal years), and slightly simplifies several calls in rpc_client.c.
Diffstat (limited to 'rpc_api.c')
-rw-r--r--rpc_api.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/rpc_api.c b/rpc_api.c
index f468d63..97c8e99 100644
--- a/rpc_api.c
+++ b/rpc_api.c
@@ -120,6 +120,8 @@ static inline int check_pkey_type_curve_flags(const hal_key_type_t type,
hal_error_t hal_rpc_get_version(uint32_t *version)
{
+ if (version == NULL)
+ return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_misc_dispatch->get_version(version);
}
@@ -184,6 +186,8 @@ hal_error_t hal_rpc_hash_get_digest_length(const hal_digest_algorithm_t alg, siz
hal_error_t hal_rpc_hash_get_digest_algorithm_id(const hal_digest_algorithm_t alg,
uint8_t *id, size_t *len, const size_t len_max)
{
+ if (id == NULL && len_max != 0)
+ return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_hash_dispatch->get_digest_algorithm_id(alg, id, len, len_max);
}
@@ -200,7 +204,7 @@ hal_error_t hal_rpc_hash_initialize(const hal_client_handle_t client,
const hal_digest_algorithm_t alg,
const uint8_t * const key, const size_t key_len)
{
- if (hash == NULL)
+ if (hash == NULL || (key == NULL && key_len != 0))
return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_hash_dispatch->initialize(client, session, hash, alg, key, key_len);
}
@@ -328,7 +332,7 @@ size_t hal_rpc_pkey_get_public_key_len(const hal_pkey_handle_t pkey)
hal_error_t hal_rpc_pkey_get_public_key(const hal_pkey_handle_t pkey,
uint8_t *der, size_t *der_len, const size_t der_max)
{
- if (der == NULL || der_len == NULL || der_max == 0)
+ if (der == NULL && der_max != 0)
return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_pkey_dispatch->get_public_key(pkey, der, der_len, der_max);
}