[MERGED] osmo-bts[master]: trx_if: Improve error handling

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
Sat Jul 1 07:38:05 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: trx_if: Improve error handling
......................................................................


trx_if: Improve error handling

There ware some error conditions that the previous code didn't catch
and/or report, such as unparseable TRX control strings, non-terminated
buffers, ...

Change-Id: I354d0c121880553ce1bd59b7394d52b104b7d6da
---
M src/osmo-bts-trx/trx_if.c
1 file changed, 8 insertions(+), 3 deletions(-)

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



diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index b15d24d..2486894 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -6,7 +6,7 @@
  * sockets and their respective protocol encoding/parsing.
  *
  * Copyright (C) 2013  Andreas Eversberg <jolly at eversberg.eu>
- * Copyright (C) 2016  Harald Welte <laforge at gnumonks.org>
+ * Copyright (C) 2016-2017  Harald Welte <laforge at gnumonks.org>
  *
  * All Rights Reserved
  *
@@ -84,7 +84,7 @@
 /* close socket + unregister osmo_fd */
 static void trx_udp_close(struct osmo_fd *ofd)
 {
-	if (ofd->fd > 0) {
+	if (ofd->fd >= 0) {
 		osmo_fd_unregister(ofd);
 		close(ofd->fd);
 		ofd->fd = -1;
@@ -116,7 +116,11 @@
 		return 0;
 	}
 
-	sscanf(buf, "IND CLOCK %u", &fn);
+	if (sscanf(buf, "IND CLOCK %u", &fn) != 1) {
+		LOGP(DTRX, LOGL_ERROR, "Unable to parse '%s'\n", buf);
+		return 0;
+	}
+
 	LOGP(DTRX, LOGL_INFO, "Clock indication: fn=%u\n", fn);
 
 	if (fn >= GSM_HYPERFRAME) {
@@ -208,6 +212,7 @@
 		va_end(ap);
 	} else
 		snprintf(tcm->cmd, sizeof(tcm->cmd)-1, "CMD %s", cmd);
+	tcm->cmd[sizeof(tcm->cmd)-1] = '\0';
 	tcm->cmd_len = strlen(cmd);
 	tcm->critical = critical;
 	llist_add_tail(&tcm->list, &l1h->trx_ctrl_list);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I354d0c121880553ce1bd59b7394d52b104b7d6da
Gerrit-PatchSet: 3
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list