[Cryptech-Commits] [sw/libhal] 04/05: stupid fixes
git at cryptech.is
git at cryptech.is
Tue Mar 22 03:06:39 UTC 2016
This is an automated email from the git hooks/post-receive script.
paul at psgd.org pushed a commit to branch rpc
in repository sw/libhal.
commit cdaf07d30bd440cf3ee2f6615d044634734047bd
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Mon Mar 21 22:35:48 2016 -0400
stupid fixes
---
.gitignore | 1 +
GNUmakefile | 4 ++--
rpc_server.c | 5 ++---
tests/GNUmakefile | 2 +-
tests/test-rpc_get_version.c | 20 ++++++++++++++++++++
xdr.c | 22 ++++++++++++----------
6 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/.gitignore b/.gitignore
index aa56703..b5ca513 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,5 +16,6 @@ tests/test-rpc_server
tests/test-rsa
tests/test-rsa-*.der
tests/test-trng
+tests/test-rpc_get_version
utils/cores
utils/eim_peek_poke
diff --git a/GNUmakefile b/GNUmakefile
index 66f04cb..75bcf44 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -78,7 +78,7 @@ endif
# loopback: communicate over loopback socket on Novena
# serial: communicate over USB in serial pass-through mode
-RPC_CORE_OBJ = rpc_api.o rpc_hash.o rpc_misc.o rpc_pkey.o
+RPC_CORE_OBJ = rpc_hash.o rpc_misc.o rpc_pkey.o
ifdef RPC_SERVER
RPC_SERVER_OBJ = rpc_server.o ${RPC_CORE_OBJ}
@@ -86,7 +86,7 @@ ifdef RPC_SERVER
endif
ifdef RPC_CLIENT
- RPC_CLIENT_OBJ = rpc_client.o
+ RPC_CLIENT_OBJ = rpc_client.o rpc_api.o
ifeq (${RPC_CLIENT},local)
RPC_CLIENT_OBJ += ${RPC_CORE_OBJ}
else
diff --git a/rpc_server.c b/rpc_server.c
index d57fc57..6b3514c 100644
--- a/rpc_server.c
+++ b/rpc_server.c
@@ -50,8 +50,6 @@ static hal_error_t get_version(uint8_t **iptr, const uint8_t * const ilimit,
uint32_t version;
hal_error_t ret;
- check(hal_xdr_encode_int(optr, olimit, RPC_VERSION));
-
/* call the local function */
ret = hal_rpc_local_misc_dispatch.get_version(&version);
if (ret == HAL_OK)
@@ -605,7 +603,8 @@ void hal_rpc_server_main(void)
while (!interrupt) {
ilen = sizeof(inbuf);
- if (hal_rpc_recvfrom(inbuf, &ilen, &opaque) == HAL_OK) {
+ ret = hal_rpc_recvfrom(inbuf, &ilen, &opaque);
+ if (ret == HAL_OK) {
iptr = inbuf;
ilimit = inbuf + ilen;
optr = outbuf + 4; /* reserve 4 bytes for return code */
diff --git a/tests/GNUmakefile b/tests/GNUmakefile
index b4d006d..0fa6281 100644
--- a/tests/GNUmakefile
+++ b/tests/GNUmakefile
@@ -40,7 +40,7 @@ ifndef RPC_SERVER
endif
endif
ifdef RPC_CLIENT
- BIN += test-rpc_hash
+ BIN += test-rpc_hash test-rpc_get_version
endif
ifdef RPC_SERVER
BIN += test-rpc_server
diff --git a/tests/test-rpc_get_version.c b/tests/test-rpc_get_version.c
new file mode 100644
index 0000000..84869c3
--- /dev/null
+++ b/tests/test-rpc_get_version.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include <hal.h>
+#include <hal_internal.h>
+
+int main (int argc, char *argv[])
+{
+ uint32_t version;
+
+#define check(op) { hal_error_t err; if ((err = (op)) != HAL_OK) { printf("%s: %s\n", #op, hal_error_string(err)); return 1; } }
+
+ check(hal_rpc_client_init());
+ check(hal_rpc_get_version(&version));
+ printf("%08x\n", version);
+
+ return 0;
+}
diff --git a/xdr.c b/xdr.c
index 2741752..42f0793 100644
--- a/xdr.c
+++ b/xdr.c
@@ -157,15 +157,6 @@ hal_error_t hal_xdr_decode_buffer_in_place(uint8_t **inbuf, const uint8_t * cons
return HAL_ERROR_IO_BAD_COUNT;
}
- /* user buffer is too small, update *len
- */
- if (*len < xdr_len) {
- *len = xdr_len;
- /* undo read of length */
- *inbuf = orig_inbuf;
- return HAL_ERROR_IO_BAD_COUNT;
- }
-
/* return a pointer to the string or opaque data */
*value = *inbuf;
*len = xdr_len;
@@ -183,9 +174,20 @@ hal_error_t hal_xdr_decode_buffer(uint8_t **inbuf, const uint8_t * const limit,
{
hal_error_t ret;
uint8_t *vptr;
+ uint8_t *orig_inbuf = *inbuf;
+ uint32_t xdr_len;
+
+ if ((ret = hal_xdr_decode_buffer_in_place(inbuf, limit, &vptr, &xdr_len)) == HAL_OK) {
+ if (*len < xdr_len) {
+ /* user buffer is too small, update *len */
+ *len = xdr_len;
+ /* undo read of length */
+ *inbuf = orig_inbuf;
+ return HAL_ERROR_IO_BAD_COUNT;
+ }
- if ((ret = hal_xdr_decode_buffer_in_place(inbuf, limit, &vptr, len)) == HAL_OK)
memcpy(value, vptr, *len);
+ }
return ret;
}
More information about the Commits
mailing list