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

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(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/40/3040/1

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 <[email protected]>
- * Copyright (C) 2016  Harald Welte <[email protected]>
+ * Copyright (C) 2016-2017  Harald Welte <[email protected]>
  *
  * 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: newchange
Gerrit-Change-Id: I354d0c121880553ce1bd59b7394d52b104b7d6da
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <[email protected]>

Reply via email to