daniel has uploaded this change for review. ( 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(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sysmon refs/changes/53/9453/1

diff --git a/simple_ctrl.c b/simple_ctrl.c
index e585fac..5c339b4 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: newchange
Gerrit-Change-Id: Ieaa9b3e2516d301ba45b6f3ec61870e928ed0cc6
Gerrit-Change-Number: 9453
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillm...@sysmocom.de>

Reply via email to