Hello Jenkins Builder,

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

    https://gerrit.osmocom.org/6198

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

Wrap osmo_strlcpy() calls

Using following semantic patch:
@@ expression A, B, C; @@
- osmo_strlcpy(A, B, sizeof(A));
+ OSMO_STRLCPY_ARRAY(A, B);

Which was applied using following command:
spatch --dir src -I src --sp-file strlcpy.spatch --in-place --recursive-includes

All the calls to osmo_strlcpy() which use destination buffer obtained
via sizeof() were replaced with the corresponding wrapper macro.

Change-Id: I67b482dedfa11237ac21894fc5930039e12434ab
Related: OS#2864
---
M src/libcommon/gsup_test_client.c
M src/libmsc/db.c
M src/libmsc/gsm_04_08.c
M src/libmsc/gsm_04_11.c
M src/libmsc/smpp_openbsc.c
M src/libmsc/sms_queue.c
M src/libvlr/vlr.c
7 files changed, 34 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/98/6198/2

diff --git a/src/libcommon/gsup_test_client.c b/src/libcommon/gsup_test_client.c
index 8605040..be8e768 100644
--- a/src/libcommon/gsup_test_client.c
+++ b/src/libcommon/gsup_test_client.c
@@ -75,7 +75,7 @@
                return NULL;
 
        io = talloc_zero(ctx, struct imsi_op);
-       osmo_strlcpy(io->imsi, imsi, sizeof(io->imsi));
+       OSMO_STRLCPY_ARRAY(io->imsi, imsi);
        io->type = type;
        osmo_timer_setup(&io->timer, imsi_op_timer_cb, io);
        llist_add(&io->list, &g_imsi_ops);
@@ -107,7 +107,7 @@
        struct osmo_gsup_message gsup = {0};
        struct msgb *msg = msgb_alloc_headroom(1200, 200, __func__);
 
-       osmo_strlcpy(gsup.imsi, io->imsi, sizeof(gsup.imsi));
+       OSMO_STRLCPY_ARRAY(gsup.imsi, io->imsi);
        gsup.message_type = OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST;
 
        osmo_gsup_encode(msg, &gsup);
@@ -122,7 +122,7 @@
        struct osmo_gsup_message gsup = {0};
        struct msgb *msg = msgb_alloc_headroom(1200, 200, __func__);
 
-       osmo_strlcpy(gsup.imsi, io->imsi, sizeof(gsup.imsi));
+       OSMO_STRLCPY_ARRAY(gsup.imsi, io->imsi);
        gsup.message_type = OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST;
 
        osmo_gsup_encode(msg, &gsup);
@@ -135,7 +135,7 @@
        struct osmo_gsup_message gsup = {0};
        struct msgb *msg = msgb_alloc_headroom(1200, 200, __func__);
 
-       osmo_strlcpy(gsup.imsi, io->imsi, sizeof(gsup.imsi));
+       OSMO_STRLCPY_ARRAY(gsup.imsi, io->imsi);
        gsup.message_type = OSMO_GSUP_MSGT_INSERT_DATA_RESULT;
 
        osmo_gsup_encode(msg, &gsup);
diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index db9989d..d06db10 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -258,7 +258,7 @@
        free(quoted);
        extension = dbi_result_get_string(result2, "extension");
        if (extension)
-               osmo_strlcpy(sms->src.addr, extension, sizeof(sms->src.addr));
+               OSMO_STRLCPY_ARRAY(sms->src.addr, extension);
        dbi_result_free(result2);
        /* got the extension */
 
@@ -271,7 +271,7 @@
 
        daddr = dbi_result_get_string(result, "dest_addr");
        if (daddr)
-               osmo_strlcpy(sms->dst.addr, daddr, sizeof(sms->dst.addr));
+               OSMO_STRLCPY_ARRAY(sms->dst.addr, daddr);
 
        sms->user_data_len = dbi_result_get_field_length(result, "user_data");
        user_data = dbi_result_get_binary(result, "user_data");
@@ -281,7 +281,7 @@
 
        text = dbi_result_get_string(result, "text");
        if (text)
-               osmo_strlcpy(sms->text, text, sizeof(sms->text));
+               OSMO_STRLCPY_ARRAY(sms->text, text);
        return sms;
 }
 
@@ -410,12 +410,12 @@
                                                  "data_coding_scheme");
 
        addr = dbi_result_get_string(result, "src_addr");
-       osmo_strlcpy(sms->src.addr, addr, sizeof(sms->src.addr));
+       OSMO_STRLCPY_ARRAY(sms->src.addr, addr);
        sms->src.ton = dbi_result_get_ulonglong(result, "src_ton");
        sms->src.npi = dbi_result_get_ulonglong(result, "src_npi");
 
        addr = dbi_result_get_string(result, "dest_addr");
-       osmo_strlcpy(sms->dst.addr, addr, sizeof(sms->dst.addr));
+       OSMO_STRLCPY_ARRAY(sms->dst.addr, addr);
        sms->dst.ton = dbi_result_get_ulonglong(result, "dest_ton");
        sms->dst.npi = dbi_result_get_ulonglong(result, "dest_npi");
 
@@ -427,7 +427,7 @@
 
        text = dbi_result_get_string(result, "text");
        if (text)
-               osmo_strlcpy(sms->text, text, sizeof(sms->text));
+               OSMO_STRLCPY_ARRAY(sms->text, text);
        return sms;
 }
 
@@ -766,14 +766,14 @@
        sms->dst.ton = dbi_result_get_ulonglong(result, "dest_ton");
        daddr = dbi_result_get_string(result, "dest_addr");
        if (daddr)
-               osmo_strlcpy(sms->dst.addr, daddr, sizeof(sms->dst.addr));
+               OSMO_STRLCPY_ARRAY(sms->dst.addr, daddr);
        sms->receiver = vlr_subscr_find_by_msisdn(net->vlr, sms->dst.addr);
 
        sms->src.npi = dbi_result_get_ulonglong(result, "src_npi");
        sms->src.ton = dbi_result_get_ulonglong(result, "src_ton");
        saddr = dbi_result_get_string(result, "src_addr");
        if (saddr)
-               osmo_strlcpy(sms->src.addr, saddr, sizeof(sms->src.addr));
+               OSMO_STRLCPY_ARRAY(sms->src.addr, saddr);
 
        sms->user_data_len = dbi_result_get_field_length(result, "user_data");
        user_data = dbi_result_get_binary(result, "user_data");
@@ -783,7 +783,7 @@
 
        text = dbi_result_get_string(result, "text");
        if (text)
-               osmo_strlcpy(sms->text, text, sizeof(sms->text));
+               OSMO_STRLCPY_ARRAY(sms->text, text);
        return sms;
 }
 
diff --git a/src/libmsc/gsm_04_08.c b/src/libmsc/gsm_04_08.c
index 5acc4e4..298acdc 100644
--- a/src/libmsc/gsm_04_08.c
+++ b/src/libmsc/gsm_04_08.c
@@ -1635,8 +1635,8 @@
 
        /* use subscriber as calling party number */
        setup.fields |= MNCC_F_CALLING;
-       osmo_strlcpy(setup.calling.number, trans->vsub->msisdn, 
sizeof(setup.calling.number));
-       osmo_strlcpy(setup.imsi, trans->vsub->imsi, sizeof(setup.imsi));
+       OSMO_STRLCPY_ARRAY(setup.calling.number, trans->vsub->msisdn);
+       OSMO_STRLCPY_ARRAY(setup.imsi, trans->vsub->imsi);
 
        /* bearer capability */
        if (TLVP_PRESENT(&tp, GSM48_IE_BEARER_CAP)) {
@@ -1824,7 +1824,7 @@
        }
 
        /* IMSI of called subscriber */
-       osmo_strlcpy(call_conf.imsi, trans->vsub->imsi, sizeof(call_conf.imsi));
+       OSMO_STRLCPY_ARRAY(call_conf.imsi, trans->vsub->imsi);
 
        new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
 
@@ -2003,8 +2003,8 @@
        tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
        /* use subscriber as connected party number */
        connect.fields |= MNCC_F_CONNECTED;
-       osmo_strlcpy(connect.connected.number, trans->vsub->msisdn, 
sizeof(connect.connected.number));
-       osmo_strlcpy(connect.imsi, trans->vsub->imsi, sizeof(connect.imsi));
+       OSMO_STRLCPY_ARRAY(connect.connected.number, trans->vsub->msisdn);
+       OSMO_STRLCPY_ARRAY(connect.imsi, trans->vsub->imsi);
 
        /* facility */
        if (TLVP_PRESENT(&tp, GSM48_IE_FACILITY)) {
diff --git a/src/libmsc/gsm_04_11.c b/src/libmsc/gsm_04_11.c
index f178fd3..62c2902 100644
--- a/src/libmsc/gsm_04_11.c
+++ b/src/libmsc/gsm_04_11.c
@@ -91,15 +91,15 @@
                return NULL;
 
        sms->receiver = vlr_subscr_get(receiver);
-       osmo_strlcpy(sms->text, text, sizeof(sms->text));
+       OSMO_STRLCPY_ARRAY(sms->text, text);
 
-       osmo_strlcpy(sms->src.addr, sender->msisdn, sizeof(sms->src.addr));
+       OSMO_STRLCPY_ARRAY(sms->src.addr, sender->msisdn);
        sms->reply_path_req = 0;
        sms->status_rep_req = 0;
        sms->ud_hdr_ind = 0;
        sms->protocol_id = 0; /* implicit */
        sms->data_coding_scheme = dcs;
-       osmo_strlcpy(sms->dst.addr, receiver->msisdn, sizeof(sms->dst.addr));
+       OSMO_STRLCPY_ARRAY(sms->dst.addr, receiver->msisdn);
        /* Generate user_data */
        sms->user_data_len = gsm_7bit_encode_n(sms->user_data, 
sizeof(sms->user_data),
                                                sms->text, NULL);
@@ -499,7 +499,7 @@
                }
        }
 
-       osmo_strlcpy(gsms->src.addr, conn->vsub->msisdn, 
sizeof(gsms->src.addr));
+       OSMO_STRLCPY_ARRAY(gsms->src.addr, conn->vsub->msisdn);
 
        LOGP(DLSMS, LOGL_INFO, "RX SMS: Sender: %s, MTI: 0x%02x, VPF: 0x%02x, "
             "MR: 0x%02x PID: 0x%02x, DCS: 0x%02x, DA: %s, "
diff --git a/src/libmsc/smpp_openbsc.c b/src/libmsc/smpp_openbsc.c
index b0469f9..c12db5f 100644
--- a/src/libmsc/smpp_openbsc.c
+++ b/src/libmsc/smpp_openbsc.c
@@ -152,16 +152,15 @@
        sms->dst.ton = submit->dest_addr_ton;
        sms->dst.npi = submit->dest_addr_npi;
        if (dest)
-               osmo_strlcpy(sms->dst.addr, dest->msisdn, 
sizeof(sms->dst.addr));
+               OSMO_STRLCPY_ARRAY(sms->dst.addr, dest->msisdn);
        else
-               osmo_strlcpy(sms->dst.addr, (const char 
*)submit->destination_addr,
-                            sizeof(sms->dst.addr));
+               OSMO_STRLCPY_ARRAY(sms->dst.addr,
+                                  (const char *)submit->destination_addr);
 
        /* fill in the source address */
        sms->src.ton = submit->source_addr_ton;
        sms->src.npi = submit->source_addr_npi;
-       osmo_strlcpy(sms->src.addr, (char *)submit->source_addr,
-                    sizeof(sms->src.addr));
+       OSMO_STRLCPY_ARRAY(sms->src.addr, (char *)submit->source_addr);
 
        if (submit->esm_class == SMPP34_DELIVERY_ACK)
                sms->is_report = true;
diff --git a/src/libmsc/sms_queue.c b/src/libmsc/sms_queue.c
index 163d4c7..39a81f6 100644
--- a/src/libmsc/sms_queue.c
+++ b/src/libmsc/sms_queue.c
@@ -205,8 +205,7 @@
        int sanity = 100;
        char started_with_msisdn[last_msisdn_buflen];
 
-       osmo_strlcpy(started_with_msisdn, last_msisdn,
-                    sizeof(started_with_msisdn));
+       OSMO_STRLCPY_ARRAY(started_with_msisdn, last_msisdn);
 
        while (wrapped < 2 && (--sanity)) {
                /* If we wrapped around and passed the first msisdn, we're
diff --git a/src/libvlr/vlr.c b/src/libvlr/vlr.c
index 6750a46..2b9e3b2 100644
--- a/src/libvlr/vlr.c
+++ b/src/libvlr/vlr.c
@@ -152,7 +152,7 @@
        struct vlr_instance *vlr = vsub->vlr;
 
        if (strlen(gsup_msg->imsi) == 0)
-               osmo_strlcpy(gsup_msg->imsi, vsub->imsi, 
sizeof(gsup_msg->imsi));
+               OSMO_STRLCPY_ARRAY(gsup_msg->imsi, vsub->imsi);
 
        return vlr_tx_gsup_message(vlr, gsup_msg);
 }
@@ -164,7 +164,7 @@
 {
        struct osmo_gsup_message gsup_reply = {0};
 
-       osmo_strlcpy(gsup_reply.imsi, gsup_orig->imsi, sizeof(gsup_reply.imsi));
+       OSMO_STRLCPY_ARRAY(gsup_reply.imsi, gsup_orig->imsi);
        gsup_reply.cause = cause;
        gsup_reply.message_type =
                OSMO_GSUP_TO_MSGT_ERROR(gsup_orig->message_type);
@@ -368,7 +368,7 @@
 {
        if (!vsub)
                return;
-       osmo_strlcpy(vsub->imsi, imsi, sizeof(vsub->imsi));
+       OSMO_STRLCPY_ARRAY(vsub->imsi, imsi);
        vsub->id = atoll(vsub->imsi);
        DEBUGP(DVLR, "set IMSI on subscriber; IMSI=%s id=%llu\n",
               vsub->imsi, vsub->id);
@@ -378,7 +378,7 @@
 {
        if (!vsub)
                return;
-       osmo_strlcpy(vsub->imei, imei, sizeof(vsub->imei));
+       OSMO_STRLCPY_ARRAY(vsub->imei, imei);
        DEBUGP(DVLR, "set IMEI on subscriber; IMSI=%s IMEI=%s\n",
               vsub->imsi, vsub->imei);
 }
@@ -387,7 +387,7 @@
 {
        if (!vsub)
                return;
-       osmo_strlcpy(vsub->imeisv, imeisv, sizeof(vsub->imeisv));
+       OSMO_STRLCPY_ARRAY(vsub->imeisv, imeisv);
        DEBUGP(DVLR, "set IMEISV on subscriber; IMSI=%s IMEISV=%s\n",
               vsub->imsi, vsub->imeisv);
 }
@@ -397,7 +397,7 @@
 {
        if (!vsub)
                return;
-       osmo_strlcpy(vsub->msisdn, msisdn, sizeof(vsub->msisdn));
+       OSMO_STRLCPY_ARRAY(vsub->msisdn, msisdn);
        DEBUGP(DVLR, "set MSISDN on subscriber; IMSI=%s MSISDN=%s\n",
               vsub->imsi, vsub->msisdn);
 }
@@ -566,7 +566,7 @@
        struct osmo_gsup_message gsup_msg = {0};
 
        gsup_msg.message_type = OSMO_GSUP_MSGT_AUTH_FAIL_REPORT;
-       osmo_strlcpy(gsup_msg.imsi, vsub->imsi, sizeof(gsup_msg.imsi));
+       OSMO_STRLCPY_ARRAY(gsup_msg.imsi, vsub->imsi);
        return vlr_tx_gsup_message(vsub->vlr, &gsup_msg);
 }
 

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I67b482dedfa11237ac21894fc5930039e12434ab
Gerrit-PatchSet: 2
Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-Owner: Max <msur...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder

Reply via email to