client: use osmo_strlcpy instead of strncpy
simplify \nul termination of the ip_addr string
Change-Id: I94e3815f45d08e0d40faf41e580547de937c4ce8
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 7e83f95..5cd14f7 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -200,8 +200,7 @@
goto response_parse_failure;
/* Extract IP-Address */
- strncpy(r->audio_ip, line + 9, sizeof(r->audio_ip));
- r->audio_ip[sizeof(r->audio_ip) - 1] = '\0';
+ osmo_strlcpy(r->audio_ip, line + 9, sizeof(r->audio_ip));
/* Check IP-Address */
if (inet_aton(r->audio_ip, &ip_test) == 0)
@@ -397,7 +396,7 @@
unsigned int l = msg->len < sizeof(strbuf) ? msg->len : sizeof(strbuf);
unsigned int i;
- strncpy(strbuf, (const char*)msg->data, l);
+ osmo_strlcpy(strbuf, (const char*)msg->data, l);
for (i = 0; i < sizeof(strbuf); i++) {
if (strbuf[i] == '\n' || strbuf[i] == '\r') {
strbuf[i] = '\0';
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index e33596d..dcfc2ff 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -29,7 +29,8 @@
#include <ctype.h>
/* Allocate a new connection identifier. According to RFC3435, they must
- * be unique only within the scope of the endpoint. */
+ * be unique only within the scope of the endpoint. (Caller must provide
+ * memory for id) */
static int mgcp_alloc_id(struct mgcp_endpoint *endp, char *id)
{
int i;
@@ -140,7 +141,7 @@
conn->mode = MGCP_CONN_NONE;
conn->mode_orig = MGCP_CONN_NONE;
conn->u.rtp.conn = conn;
- strcpy(conn->name, name);
+ osmo_strlcpy(conn->name, name, sizeof(conn->name));
rc = mgcp_alloc_id(endp, conn->id);
if (rc < 0) {
talloc_free(conn);
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index a02b0d1..816f16b 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -88,7 +88,7 @@
if (endp->cfg->net_ports.bind_addr) {
/* Check there is a bind IP for the RTP traffic configured,
* if so, use that IP-Address */
- strncpy(addr, endp->cfg->net_ports.bind_addr, INET_ADDRSTRLEN);
+ osmo_strlcpy(addr, endp->cfg->net_ports.bind_addr, INET_ADDRSTRLEN);
LOGP(DRTP, LOGL_DEBUG,
"endpoint:%x CI:%s using configured rtp bind ip as local bind ip %s\n",
ENDPOINT_NUMBER(endp), conn->conn->id, addr);
@@ -96,7 +96,7 @@
/* No specific bind IP is configured for the RTP traffic, so
* assume the IP where we listen for incoming MGCP messages
* as bind IP */
- strncpy(addr, endp->cfg->source_addr, INET_ADDRSTRLEN);
+ osmo_strlcpy(addr, endp->cfg->source_addr, INET_ADDRSTRLEN);
LOGP(DRTP, LOGL_DEBUG,
"endpoint:%x CI:%s using mgcp bind ip as local rtp bind ip: %s\n",
ENDPOINT_NUMBER(endp), conn->conn->id, addr);