]> git.meshlink.io Git - meshlink/commitdiff
Make sure header src and dst are always null-terminated.
authorAaron Krebs <aaron.krebs@everbase.net>
Mon, 1 Dec 2014 15:52:54 +0000 (16:52 +0100)
committerGuus Sliepen <guus@meshlink.io>
Sat, 27 Dec 2014 17:37:02 +0000 (18:37 +0100)
src/meshlink.c

index 918a62b6e500c8affcd01c3763e21cab27276247..8b97be7913552d95f1537155e8ebb8b5fa8c45b3 100644 (file)
@@ -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);