From b26c53cb0f66865524cdee72f4ff916f63bcdba3 Mon Sep 17 00:00:00 2001 From: Diogo Diniz Date: Mon, 29 Jun 2026 15:11:33 +0100 Subject: [PATCH] chore: Several comments --- app/src/incphub/src/incphub_client.c | 2 +- app/src/incphub/src/incphub_task.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/incphub/src/incphub_client.c b/app/src/incphub/src/incphub_client.c index dd090eb..4d9e133 100644 --- a/app/src/incphub/src/incphub_client.c +++ b/app/src/incphub/src/incphub_client.c @@ -48,7 +48,7 @@ int incphub_send_local(incphub_cli_t *cli, uint8_t *buffer, size_t length, ntl_p if (dst_port == NTL_PORT_EMPTY) return INCPHUB_EINVAL; - // Unwind pointer + // Unwind buffer pointer ntl_packet_t *ntl_packet = (ntl_packet_t*)(buffer - sizeof(ntl_header_t)); nil_packet_t *nil_packet = (nil_packet_t*)(ntl_packet - sizeof(ntl_header_t)); size_t extended_len = sizeof(nil_header_t) + sizeof(ntl_header_t) + length; diff --git a/app/src/incphub/src/incphub_task.c b/app/src/incphub/src/incphub_task.c index da757b7..83f4c5a 100644 --- a/app/src/incphub/src/incphub_task.c +++ b/app/src/incphub/src/incphub_task.c @@ -57,10 +57,12 @@ void incphub_task_main(void *params) while (1) { + // Dequeue message uint8_t *buffer; size_t length; dequeue_message_ingest(&buffer, &length); + // Get NIL packet nil_packet_t *nil = extract_nil_packet(buffer, length); if (nil == NULL) { @@ -68,6 +70,7 @@ void incphub_task_main(void *params) continue; } + // Process or route handle_nil_packet(nil); } } @@ -77,6 +80,7 @@ void incphub_task_main(void *params) // === Private functions === static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length) { + // Ensure message is big enough to hold a packet if (length < sizeof(nil_packet_t)) { //TODO: Error @@ -84,10 +88,11 @@ static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length) } nil_packet_t *nil = (nil_packet_t *)buffer; + // Ensure length field is not going to cause buffer overflow if (length < sizeof(nil_packet_t) + nil->header.len ) { //TODO: Error - return NULL;; + return NULL; } return nil; @@ -95,6 +100,7 @@ static nil_packet_t *extract_nil_packet(uint8_t *buffer, size_t length) static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil) { + // Ensure message is big enough to hold a packet if (nil->header.len < sizeof(ntl_packet_t)) { //TODO: Error @@ -102,7 +108,7 @@ static ntl_packet_t *extract_ntl_packet(nil_packet_t *nil) } ntl_packet_t *ntl = (ntl_packet_t *)nil->payload; - + // Ensure length field is not going to cause buffer overflow if (nil->header.len < sizeof(ntl_packet_t) + ntl->header.len) { //TODO: Error