diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-06-24 17:20:58 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-07-01 07:38:01 +0000 |
commit | bb719478293f1961257085bd6a06b4a3d44d3e06 (patch) | |
tree | b0ac55cc9ad2850a72f7c4b2363d79b270784fd9 | |
parent | c19ab9ed2fca26c0efa9a887a147ed3391c56a19 (diff) |
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
-rw-r--r-- | src/osmo-bts-trx/trx_if.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c index b15d24df..2486894a 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@eversberg.eu> - * Copyright (C) 2016 Harald Welte <laforge@gnumonks.org> + * Copyright (C) 2016-2017 Harald Welte <laforge@gnumonks.org> * * All Rights Reserved * @@ -84,7 +84,7 @@ static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host_local, /* 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 @@ static int trx_clk_read_cb(struct osmo_fd *ofd, unsigned int what) 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 @@ static int trx_ctrl_cmd(struct trx_l1h *l1h, int critical, const char *cmd, 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); |