From 34eca987e2b3f8c08cf386a644beb7465324f638 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 7 May 2024 18:55:09 +0200 Subject: better error handling --- ecp/src/ecp/core.c | 18 +++++++++--------- ecp/src/ecp/core.h | 12 +++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c index 7d61def..03fa815 100644 --- a/ecp/src/ecp/core.c +++ b/ecp/src/ecp/core.c @@ -1699,7 +1699,7 @@ ssize_t ecp_handle_init_req(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_ if (msg_size < ECP_SIZE_ZPAD_PLD) return ECP_ERR_SIZE; for (i=0; irefcount++; @@ -2278,7 +2278,7 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, unsigned char *zpad_buf; int i; - if (pkt_size < (ECP_MIN_PKT+ECP_SIZE_ZPAD_HDR+ECP_SIZE_ZPAD_PLD)) return ECP_ERR_SIZE; + if (pkt_size < (ECP_MIN_PKT+ECP_SIZE_ZPAD_HDR+ECP_SIZE_ZPAD_PLD)) return ECP_ERR_PKT; zpad_buf = public_buf+ECP_SIZE_ECDH_PUB; nonce_buf = zpad_buf+ECP_SIZE_ZPAD_HDR; @@ -2286,16 +2286,18 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, pkt_size -= ECP_SIZE_PKT_HDR_IREQ; for (i=0; i= (ECP_MIN_PKT+ECP_SIZE_COOKIE)) { + } else { /* open request message */ unsigned char *cookie_buf; + if (pkt_size < (ECP_MIN_PKT+ECP_SIZE_COOKIE)) return ECP_ERR_PKT; + cookie_buf = public_buf+ECP_SIZE_ECDH_PUB; nonce_buf = cookie_buf+ECP_SIZE_COOKIE; packet += ECP_SIZE_PKT_HDR_OREQ; @@ -2308,11 +2310,9 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPConnection *parent, ecp_tr_addr_t *addr, if (_rv) return _rv; ecp_ecdh_shkey(&shkey, (ecp_ecdh_public_t *)public_buf, &key.private); - } else { - return ECP_ERR; } } else { - return ECP_ERR; + return ECP_ERR_PKT; } ecp_buf2nonce(&nonce_pkt, nonce_buf); diff --git a/ecp/src/ecp/core.h b/ecp/src/ecp/core.h index 5d8cd47..8b76895 100644 --- a/ecp/src/ecp/core.h +++ b/ecp/src/ecp/core.h @@ -21,13 +21,15 @@ #define ECP_ERR_MTYPE -9 #define ECP_ERR_CTYPE -10 #define ECP_ERR_HANDLER -11 -#define ECP_ERR_COOKIE -12 +#define ECP_ERR_PKT -12 +#define ECP_ERR_ZPAD -13 +#define ECP_ERR_COOKIE -14 -#define ECP_ERR_NET_ADDR -13 -#define ECP_ERR_MAX_PARENT -14 -#define ECP_ERR_NEXT -15 +#define ECP_ERR_NET_ADDR -20 +#define ECP_ERR_MAX_PARENT -21 +#define ECP_ERR_NEXT -22 -#define ECP_ERR_ECDH_IDX -22 +#define ECP_ERR_ECDH_IDX -25 #define ECP_ERR_ENCRYPT -26 #define ECP_ERR_DECRYPT -27 #define ECP_ERR_SIGN -28 -- cgit v1.2.3