Browse Source

hotplug.c: Make sure hotplug buffer is NULL terminated

Sets the final byte explicitly to NULL because we later do string
operations on this buffer.

Fixes Coverity issue 1430926 String not null terminated

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Hauke Mehrtens 5 years ago
parent
commit
e2b055edf2
1 changed files with 3 additions and 1 deletions
  1. 3 1
      plug/hotplug.c

+ 3 - 1
plug/hotplug.c

@@ -545,11 +545,13 @@ static void hotplug_handler(struct uloop_fd *u, unsigned int ev)
 {
 	int i = 0;
 	static char buf[4096];
-	int len = recv(u->fd, buf, sizeof(buf), MSG_DONTWAIT);
+	int len = recv(u->fd, buf, sizeof(buf) - 1, MSG_DONTWAIT);
 	void *index;
 	if (len < 1)
 		return;
 
+	buf[len] = '\0';
+
 	blob_buf_init(&b, 0);
 	index = blobmsg_open_table(&b, NULL);
 	while (i < len) {