Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/5024

to look at the new patch set (#5).

client: use osmo_strlcpy instead of strncpy

simplify \nul termination of the ip_addr string

Change-Id: I94e3815f45d08e0d40faf41e580547de937c4ce8
---
M src/libosmo-mgcp-client/mgcp_client.c
M src/libosmo-mgcp/mgcp_conn.c
M src/libosmo-mgcp/mgcp_network.c
M tests/mgcp_client/mgcp_client_test.c
4 files changed, 10 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/24/5024/5

diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index ac86f52..ee8d267 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -201,8 +201,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)
@@ -398,7 +397,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);
diff --git a/tests/mgcp_client/mgcp_client_test.c 
b/tests/mgcp_client/mgcp_client_test.c
index 5fd59e9..37fe0b8 100644
--- a/tests/mgcp_client/mgcp_client_test.c
+++ b/tests/mgcp_client/mgcp_client_test.c
@@ -46,14 +46,14 @@
        l = strlen(head);
        msg->l2h = msgb_put(msg, l);
        data = (char*)msgb_l2(msg);
-       strncpy(data, head, l);
+       osmo_strlcpy(data, head, l);
 
        data = (char*)msgb_put(msg, 1);
        *data = '\n';
 
        l = strlen(params);
        data = (char*)msgb_put(msg, l);
-       strncpy(data, params, l);
+       osmo_strlcpy(data, params, l);
 
        return msg;
 }
@@ -66,7 +66,7 @@
        char *data;
        msg->l2h = msgb_put(msg, l);
        data = (char*)msgb_l2(msg);
-       strncpy(data, str, l);
+       osmo_strlcpy(data, str, l);
        return msg;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/5024
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I94e3815f45d08e0d40faf41e580547de937c4ce8
Gerrit-PatchSet: 5
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: dexter <[email protected]>

Reply via email to