[PATCH] osmo-trx[master]: Transceiver.cpp: properly zero-terminate received commands

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/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Thu Mar 8 22:46:30 UTC 2018


Review at  https://gerrit.osmocom.org/7171

Transceiver.cpp: properly zero-terminate received commands

Previously it was assumed that a sender should zero-terminate
each command being sent. Otherwise, this could cause to printing
garbage. Let's do this manually, using the length of received
data as a position for '\0'.

Change-Id: I69f413f33156c38a853efc5a8cdc66fbfb0ca6af
---
M Transceiver52M/Transceiver.cpp
1 file changed, 9 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/71/7171/1

diff --git a/Transceiver52M/Transceiver.cpp b/Transceiver52M/Transceiver.cpp
index 7dc4c1c..8f41c5e 100644
--- a/Transceiver52M/Transceiver.cpp
+++ b/Transceiver52M/Transceiver.cpp
@@ -661,20 +661,20 @@
 
 void Transceiver::driveControl(size_t chan)
 {
-  // check control socket
-  char buffer[MAX_PACKET_LENGTH];
-  int msgLen = -1;
-  buffer[0] = '\0';
+  char buffer[MAX_PACKET_LENGTH + 1];
+  char response[MAX_PACKET_LENGTH + 1];
+  int msgLen;
 
-  msgLen = mCtrlSockets[chan]->read(buffer, sizeof(buffer));
-
-  if (msgLen < 1) {
+  /* Attempt to read from control socket */
+  msgLen = mCtrlSockets[chan]->read(buffer, MAX_PACKET_LENGTH);
+  if (msgLen < 1)
     return;
-  }
+
+  /* Zero-terminate received string */
+  buffer[msgLen] = '\0';
 
   char cmdcheck[4];
   char command[MAX_PACKET_LENGTH];
-  char response[MAX_PACKET_LENGTH];
 
   sscanf(buffer,"%3s %s",cmdcheck,command);
 

-- 
To view, visit https://gerrit.osmocom.org/7171
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I69f413f33156c38a853efc5a8cdc66fbfb0ca6af
Gerrit-PatchSet: 1
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list