[Cryptech-Commits] [sw/libhal] branch master updated: Check and propagate XDR error codes, to detect bad request packets.

git at cryptech.is git at cryptech.is
Fri Jul 8 00:10:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch master
in repository sw/libhal.

The following commit(s) were added to refs/heads/master by this push:
       new  ec8b12c   Check and propagate XDR error codes, to detect bad request packets.
ec8b12c is described below

commit ec8b12c7e7c0544c9770b626ee263e58ada9a15d
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Thu Jul 7 20:02:37 2016 -0400

    Check and propagate XDR error codes, to detect bad request packets.
---
 hal.h        |  2 +-
 rpc_server.c | 21 +++++++++++----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hal.h b/hal.h
index 04dab48..8d4786a 100644
--- a/hal.h
+++ b/hal.h
@@ -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..7f6a5f6 100644
--- a/rpc_server.c
+++ b/rpc_server.c
@@ -647,8 +647,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 +658,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 +750,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 +771,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);
         }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Commits mailing list