aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-trx/trx_if.c
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2021-04-27 18:20:07 +0200
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2021-04-30 21:07:41 +0200
commitc9635b0ad1f61bf7b735c3d083515f8337835b71 (patch)
tree4bb614448fb6455f640356f676b943336b57e1a5 /src/osmo-bts-trx/trx_if.c
parent38cdafd65616a1b2eaa171def0e9a33d255cb7fe (diff)
osmo-bts-trx: refactor parse_rsp(), fix compilation warnings
For a long time, we see this annoying -Wstringop-truncation warning: In function ‘parse_rsp’, inlined from ‘trx_ctrl_read_cb’ at trx_if.c:647:6: trx_if.c:416:2: warning: ‘strncat’ output may be truncated copying between 0 and 45 bytes from a string of length 1495 416 | strncat(rsp->cmd, buf_in + 4, p - buf_in - 4); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There is no real need to use strncat() in parse_rsp(), because we do not concatenate any strings but simply copy TRXC response parts from the input buffer to the corresponding 'name' and 'parameters' buffers. Let's use memcpy() instead. This also fixes the warning. Change-Id: Ia10adf7d76abe9a423b07e828852fbfb53b95125
Diffstat (limited to 'src/osmo-bts-trx/trx_if.c')
-rw-r--r--src/osmo-bts-trx/trx_if.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index 18c5011a..ff631874 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -397,6 +397,7 @@ struct trx_ctrl_rsp {
static int parse_rsp(const char *buf_in, size_t len_in, struct trx_ctrl_rsp *rsp)
{
+ size_t nlen, plen;
char *p, *k;
if (strncmp(buf_in, "RSP ", 4))
@@ -406,14 +407,17 @@ static int parse_rsp(const char *buf_in, size_t len_in, struct trx_ctrl_rsp *rsp
if (!(p = strchr(buf_in + 4, ' ')))
goto parse_err;
- if (p - buf_in >= sizeof(rsp->cmd)) {
- LOGP(DTRX, LOGL_ERROR, "cmd buffer too small %lu >= %zu\n",
- (long unsigned) (p - buf_in), sizeof(rsp->cmd));
+ /* Calculate length of the name part */
+ nlen = p - (buf_in + 4);
+
+ if (nlen >= sizeof(rsp->cmd)) {
+ LOGP(DTRX, LOGL_ERROR, "TRXC command name part is too long: "
+ "%zu >= %zu\n", nlen, sizeof(rsp->cmd));
goto parse_err;
}
- rsp->cmd[0] = '\0';
- strncat(rsp->cmd, buf_in + 4, p - buf_in - 4);
+ memcpy(&rsp->cmd[0], buf_in + 4, nlen);
+ rsp->cmd[nlen] = '\0';
/* Now comes the status code of the response */
p++;
@@ -427,18 +431,22 @@ static int parse_rsp(const char *buf_in, size_t len_in, struct trx_ctrl_rsp *rsp
else
k = p + strlen(p);
- if (strlen(k) >= sizeof(rsp->params)) {
- LOGP(DTRX, LOGL_ERROR, "params buffer too small %zu >= %zu\n",
- strlen(k), sizeof(rsp->params));
+ /* Calculate length of the parameters part */
+ plen = strlen(k);
+
+ if (plen >= sizeof(rsp->params)) {
+ LOGP(DTRX, LOGL_ERROR, "TRXC command parameters part is too long: "
+ "%zu >= %zu\n", plen, sizeof(rsp->params));
goto parse_err;
}
- rsp->params[0] = '\0';
- strcat(rsp->params, k);
+
+ memcpy(&rsp->params[0], k, plen);
+ rsp->params[plen] = '\0';
+
return 0;
parse_err:
- LOGP(DTRX, LOGL_NOTICE, "Unknown message on ctrl port: %s\n",
- buf_in);
+ LOGP(DTRX, LOGL_NOTICE, "Unknown TRXC message: %s\n", buf_in);
return -1;
}