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
This commit is contained in:
Max 2018-02-05 12:57:06 +01:00
parent c2007855ce
commit 98f7467ac8
7 changed files with 34 additions and 36 deletions

View File

@ -75,7 +75,7 @@ static struct imsi_op *imsi_op_alloc(void *ctx, const char *imsi,
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 @@ int req_auth_info(const char *imsi)
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 @@ int req_loc_upd(const char *imsi)
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 @@ int resp_isd(struct imsi_op *io)
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);

View File

@ -258,7 +258,7 @@ static struct gsm_sms *sms_from_result_v3(dbi_result result)
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 @@ static struct gsm_sms *sms_from_result_v3(dbi_result result)
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 @@ static struct gsm_sms *sms_from_result_v3(dbi_result result)
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 @@ static struct gsm_sms *sms_from_result_v4(dbi_result result)
"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 @@ static struct gsm_sms *sms_from_result_v4(dbi_result result)
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 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
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 @@ static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result resul
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;
}

View File

@ -1635,8 +1635,8 @@ static int gsm48_cc_rx_setup(struct gsm_trans *trans, struct msgb *msg)
/* 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 @@ static int gsm48_cc_rx_call_conf(struct gsm_trans *trans, struct msgb *msg)
}
/* 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 @@ static int gsm48_cc_rx_connect(struct gsm_trans *trans, struct msgb *msg)
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)) {

View File

@ -91,15 +91,15 @@ struct gsm_sms *sms_from_text(struct vlr_subscr *receiver,
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 @@ static int gsm340_rx_tpdu(struct gsm_trans *trans, struct msgb *msg,
}
}
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, "

View File

@ -152,16 +152,15 @@ static int submit_to_sms(struct gsm_sms **psms, struct gsm_network *net,
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;

View File

@ -205,8 +205,7 @@ struct gsm_sms *smsq_take_next_sms(struct gsm_network *net,
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

View File

@ -152,7 +152,7 @@ static int vlr_subscr_tx_gsup_message(const struct vlr_subscr *vsub,
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 @@ static int vlr_tx_gsup_error_reply(const struct vlr_instance *vlr,
{
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 @@ void vlr_subscr_set_imsi(struct vlr_subscr *vsub, const char *imsi)
{
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 @@ void vlr_subscr_set_imei(struct vlr_subscr *vsub, const char *imei)
{
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 @@ void vlr_subscr_set_imeisv(struct vlr_subscr *vsub, const char *imeisv)
{
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 @@ void vlr_subscr_set_msisdn(struct vlr_subscr *vsub, const char *msisdn)
{
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 @@ int vlr_subscr_tx_auth_fail_rep(const struct vlr_subscr *vsub)
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);
}