Change in osmo-sysmon[master]: Add zero termination char to received ctrl cmd message

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Jun 5 17:25:53 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/9453 )

Change subject: Add zero termination char to received ctrl cmd message
......................................................................

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
---
M simple_ctrl.c
1 file changed, 7 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



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);
 }
 

-- 
To view, visit https://gerrit.osmocom.org/9453
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sysmon
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ieaa9b3e2516d301ba45b6f3ec61870e928ed0cc6
Gerrit-Change-Number: 9453
Gerrit-PatchSet: 3
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180605/1bbadc12/attachment.htm>


More information about the gerrit-log mailing list