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
This commit is contained in:
Harald Welte 2017-06-24 17:20:58 +02:00
parent c19ab9ed2f
commit bb71947829
1 changed files with 8 additions and 3 deletions

View File

@ -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);