Add zero termination char to received ctrl cmd message

The terminating NULL byte is not part of the ctrl message, so add it
afterwards.

Change-Id: Ieaa9b3e2516d301ba45b6f3ec61870e928ed0cc6
diff --git a/simple_ctrl.c b/simple_ctrl.c
index deab12c..2261323 100644
--- a/simple_ctrl.c
+++ b/simple_ctrl.c
@@ -173,7 +173,7 @@
 	}
 	len = ntohs(hh.len);
 
-	resp = msgb_alloc(len+sizeof(hh), "CTRL Rx");
+	resp = msgb_alloc(len+sizeof(hh)+1, "CTRL Rx");
 	if (!resp)
 		return NULL;
 	resp->l1h = msgb_put(resp, sizeof(hh));
@@ -196,6 +196,7 @@
 	struct msgb *resp;
 	struct ipaccess_head *ih;
 	struct ipaccess_head_ext *ihe;
+	unsigned char *tmp;
 
 	/* loop until we've received a CTRL message */
 	while (true) {
@@ -207,9 +208,12 @@
 		if (ih->proto == IPAC_PROTO_OSMO)
 			resp->l2h = resp->l2h+1;
 		ihe = (struct ipaccess_head_ext*) (resp->l1h + sizeof(*ih));
-		if (ih->proto == IPAC_PROTO_OSMO && ihe->proto == IPAC_PROTO_EXT_CTRL)
+		if (ih->proto == IPAC_PROTO_OSMO && ihe->proto == IPAC_PROTO_EXT_CTRL) {
+			/* Ensure data is NULL terminated */
+			tmp = msgb_put(resp, 1);
+			*tmp = '\0';
 			return resp;
-		else {
+		} else {
 			fprintf(stderr, "unknown IPA message %s\n", msgb_hexdump(resp));
 			msgb_free(resp);
 		}
@@ -246,7 +250,6 @@
 		return NULL;
 
 	/* FIXME: ignore any TRAP */
-	/* FIXME: check string is zero-terminated */
 	return simple_ctrl_receive(sch);
 }