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.orgHarald Welte has submitted this change and it was merged.
Change subject: Transceiver.cpp: properly zero-terminate received commands
......................................................................
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(-)
Approvals:
Pau Espin Pedrol: Looks good to me, but someone else must approve
Harald Welte: Looks good to me, approved
Jenkins Builder: Verified
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: merged
Gerrit-Change-Id: I69f413f33156c38a853efc5a8cdc66fbfb0ca6af
Gerrit-PatchSet: 2
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>