From: Aaron Krebs Date: Mon, 1 Dec 2014 15:52:54 +0000 (+0100) Subject: Make sure header src and dst are always null-terminated. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=440b86e2c14d33591bbdd6647c0831583dd49db9;p=meshlink Make sure header src and dst are always null-terminated. --- 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);