From 440b86e2c14d33591bbdd6647c0831583dd49db9 Mon Sep 17 00:00:00 2001 From: Aaron Krebs Date: Mon, 1 Dec 2014 16:52:54 +0100 Subject: [PATCH] Make sure header src and dst are always null-terminated. --- src/meshlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index 918a62b6..8b97be79 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1050,8 +1050,10 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const hdr = (meshlink_packethdr_t *)packet->data; memset(hdr, 0, sizeof *hdr); - strncpy(hdr->destination, destination->name, sizeof hdr->destination); - strncpy(hdr->source, mesh->self->name, sizeof hdr->source); + // leave the last byte as 0 to make sure strings are always + // null-terminated if they are longer than the buffer + strncpy(hdr->destination, destination->name, (sizeof hdr->destination) - 1); + strncpy(hdr->source, mesh->self->name, (sizeof hdr->source) -1 ); memcpy(packet->data + sizeof *hdr, data, len); -- 2.39.5