diff options
author | Rob Austein <sra@hactrn.net> | 2016-07-08 11:23:03 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2016-07-08 11:23:03 -0400 |
commit | 20d94fd816ad1755086501547aaffdda7916235a (patch) | |
tree | 68fca0bd5630eea82c37ef7f757201486b318ba1 | |
parent | 8642938e49752c1e645955434b15de6a28a27ebc (diff) | |
parent | 5780334a373ce55eb9ce977df185234844ac1924 (diff) |
Merge branch 'master' of https://git.cryptech.is/sw/libhal.git
-rw-r--r-- | hal.h | 2 | ||||
-rw-r--r-- | rpc_server.c | 24 |
2 files changed, 13 insertions, 13 deletions
@@ -759,7 +759,7 @@ extern hal_error_t hal_rpc_client_init(void); extern hal_error_t hal_rpc_client_close(void); extern hal_error_t hal_rpc_server_init(void); extern hal_error_t hal_rpc_server_close(void); -extern void hal_rpc_server_dispatch(const uint8_t * const ibuf, const size_t ilen, uint8_t * const obuf, size_t * const olen); +extern hal_error_t hal_rpc_server_dispatch(const uint8_t * const ibuf, const size_t ilen, uint8_t * const obuf, size_t * const olen); extern void hal_rpc_server_main(void); #endif /* _HAL_H_ */ diff --git a/rpc_server.c b/rpc_server.c index ff6367c..a0de42d 100644 --- a/rpc_server.c +++ b/rpc_server.c @@ -40,7 +40,7 @@ * RPC calls. */ -#define check(op) if ((ret = (op)) != HAL_OK) return ret; +#define check(op) do { hal_error_t _err = (op); if (_err != HAL_OK) return _err; } while (0) #define pad(n) (((n) + 3) & ~3) @@ -497,7 +497,6 @@ static hal_error_t pkey_get_public_key_len(const uint8_t **iptr, const uint8_t * hal_client_handle_t client __attribute__((unused)); hal_pkey_handle_t pkey; size_t len; - hal_error_t ret; check(hal_xdr_decode_int(iptr, ilimit, &client.handle)); check(hal_xdr_decode_int(iptr, ilimit, &pkey.handle)); @@ -647,8 +646,8 @@ static hal_error_t pkey_list(const uint8_t **iptr, const uint8_t * const ilimit, return ret; } -void hal_rpc_server_dispatch(const uint8_t * const ibuf, const size_t ilen, - uint8_t * const obuf, size_t * const olen) +hal_error_t hal_rpc_server_dispatch(const uint8_t * const ibuf, const size_t ilen, + uint8_t * const obuf, size_t * const olen) { const uint8_t * iptr = ibuf; const uint8_t * const ilimit = ibuf + ilen; @@ -658,9 +657,9 @@ void hal_rpc_server_dispatch(const uint8_t * const ibuf, const size_t ilen, uint32_t client_handle; hal_error_t ret; - hal_xdr_decode_int(&iptr, ilimit, &rpc_func_num); - hal_xdr_decode_int(&iptr, ilimit, &client_handle); - hal_xdr_undecode_int(&iptr); + check(hal_xdr_decode_int(&iptr, ilimit, &rpc_func_num)); + check(hal_xdr_decode_int(&iptr, ilimit, &client_handle)); + check(hal_xdr_undecode_int(&iptr)); switch (rpc_func_num) { case RPC_FUNC_GET_VERSION: ret = get_version(&iptr, ilimit, &optr, olimit); @@ -750,9 +749,10 @@ void hal_rpc_server_dispatch(const uint8_t * const ibuf, const size_t ilen, /* Encode opcode, client ID, and response code at the beginning of the payload */ *olen = optr - obuf; optr = obuf; - hal_xdr_encode_int(&optr, olimit, rpc_func_num); - hal_xdr_encode_int(&optr, olimit, client_handle); - hal_xdr_encode_int(&optr, olimit, ret); + check(hal_xdr_encode_int(&optr, olimit, rpc_func_num)); + check(hal_xdr_encode_int(&optr, olimit, client_handle)); + check(hal_xdr_encode_int(&optr, olimit, ret)); + return HAL_OK; } #define interrupt 0 @@ -770,8 +770,8 @@ void hal_rpc_server_main(void) ret = hal_rpc_recvfrom(inbuf, &ilen, &opaque); if (ret == HAL_OK) { olen = sizeof(outbuf); - hal_rpc_server_dispatch(inbuf, ilen, outbuf, &olen); - hal_rpc_sendto(outbuf, olen, opaque); + if (hal_rpc_server_dispatch(inbuf, ilen, outbuf, &olen) == HAL_OK) + hal_rpc_sendto(outbuf, olen, opaque); } } } |