aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/gprs
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-01-13 03:12:08 +0100
committerHarald Welte <laforge@gnumonks.org>2017-01-23 11:59:01 +0000
commit93bafb611a58293e0353320a14db298133c9d99a (patch)
tree4ba6d276b7f5e2fda43f21b765d7cca8c6b00d5e /openbsc/src/gprs
parent59504dc80fe8c0d9a18994d82586a550c7efa341 (diff)
cosmetic: use osmo_strlcpy() everywhere
Shorten some code and make obvious to the reader that the string copy is done in a safe way. Change-Id: I900726cf06d34128db22a3d3d911ee0d1423b1bd
Diffstat (limited to 'openbsc/src/gprs')
-rw-r--r--openbsc/src/gprs/gprs_gmm.c16
-rw-r--r--openbsc/src/gprs/gprs_subscriber.c12
-rw-r--r--openbsc/src/gprs/gtphub.c3
-rw-r--r--openbsc/src/gprs/gtphub_ares.c12
-rw-r--r--openbsc/src/gprs/sgsn_auth.c3
5 files changed, 23 insertions, 23 deletions
diff --git a/openbsc/src/gprs/gprs_gmm.c b/openbsc/src/gprs/gprs_gmm.c
index e3d5c7d64..88be5126e 100644
--- a/openbsc/src/gprs/gprs_gmm.c
+++ b/openbsc/src/gprs/gprs_gmm.c
@@ -42,6 +42,7 @@
#include <osmocom/core/signal.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/utils.h>
#include <osmocom/crypt/auth.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
@@ -683,11 +684,10 @@ static void extract_subscr_msisdn(struct sgsn_mm_ctx *ctx)
/* Prepend a '+' for international numbers */
if (called.plan == 1 && called.type == 1) {
ctx->msisdn[0] = '+';
- strncpy(&ctx->msisdn[1], called.number,
- sizeof(ctx->msisdn) - 1);
+ osmo_strlcpy(&ctx->msisdn[1], called.number,
+ sizeof(ctx->msisdn));
} else {
- strncpy(&ctx->msisdn[0], called.number,
- sizeof(ctx->msisdn) - 1);
+ osmo_strlcpy(ctx->msisdn, called.number, sizeof(ctx->msisdn));
}
}
@@ -725,7 +725,7 @@ static void extract_subscr_hlr(struct sgsn_mm_ctx *ctx)
return;
}
- strncpy(&ctx->hlr[0], called.number, sizeof(ctx->hlr) - 1);
+ osmo_strlcpy(ctx->hlr, called.number, sizeof(ctx->hlr));
}
#ifdef BUILD_IU
@@ -1034,10 +1034,10 @@ static int gsm48_rx_gmm_id_resp(struct sgsn_mm_ctx *ctx, struct msgb *msg)
mm_ctx_cleanup_free(ictx, "GPRS IMSI re-use");
}
}
- strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi) - 1);
+ osmo_strlcpy(ctx->imsi, mi_string, sizeof(ctx->imsi));
break;
case GSM_MI_TYPE_IMEI:
- strncpy(ctx->imei, mi_string, sizeof(ctx->imei) - 1);
+ osmo_strlcpy(ctx->imei, mi_string, sizeof(ctx->imei));
break;
case GSM_MI_TYPE_IMEISV:
break;
@@ -1138,7 +1138,7 @@ static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *ctx, struct msgb *msg,
reject_cause = GMM_CAUSE_NET_FAIL;
goto rejected;
}
- strncpy(ctx->imsi, mi_string, sizeof(ctx->imsi) - 1);
+ osmo_strlcpy(ctx->imsi, mi_string, sizeof(ctx->imsi));
#endif
}
if (ctx->ran_type == MM_CTX_T_GERAN_Gb) {
diff --git a/openbsc/src/gprs/gprs_subscriber.c b/openbsc/src/gprs/gprs_subscriber.c
index 29e21ced4..d3e2ea748 100644
--- a/openbsc/src/gprs/gprs_subscriber.c
+++ b/openbsc/src/gprs/gprs_subscriber.c
@@ -22,6 +22,7 @@
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/gsm/gsup.h>
+#include <osmocom/core/utils.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/gsup_client.h>
@@ -164,7 +165,8 @@ static int gprs_subscr_tx_gsup_message(struct gsm_subscriber *subscr,
struct msgb *msg = gsup_client_msgb_alloc();
if (strlen(gsup_msg->imsi) == 0 && subscr)
- strncpy(gsup_msg->imsi, subscr->imsi, sizeof(gsup_msg->imsi) - 1);
+ osmo_strlcpy(gsup_msg->imsi, subscr->imsi,
+ sizeof(gsup_msg->imsi));
gsup_msg->cn_domain = OSMO_GSUP_CN_DOMAIN_PS;
osmo_gsup_encode(msg, gsup_msg);
@@ -185,7 +187,8 @@ static int gprs_subscr_tx_gsup_error_reply(struct gsm_subscriber *subscr,
{
struct osmo_gsup_message gsup_reply = {0};
- strncpy(gsup_reply.imsi, gsup_orig->imsi, sizeof(gsup_reply.imsi) - 1);
+ osmo_strlcpy(gsup_reply.imsi, gsup_orig->imsi,
+ sizeof(gsup_reply.imsi));
gsup_reply.cause = cause;
gsup_reply.message_type =
OSMO_GSUP_TO_MSGT_ERROR(gsup_orig->message_type);
@@ -778,9 +781,8 @@ struct gsm_subscriber *gprs_subscr_get_or_create_by_mmctx(struct sgsn_mm_ctx *mm
subscr->flags &= ~GPRS_SUBSCRIBER_ENABLE_PURGE;
}
- strncpy(subscr->equipment.imei, mmctx->imei,
- sizeof(subscr->equipment.imei)-1);
- subscr->equipment.imei[sizeof(subscr->equipment.imei)-1] = 0;
+ osmo_strlcpy(subscr->equipment.imei, mmctx->imei,
+ sizeof(subscr->equipment.imei));
if (subscr->lac != mmctx->ra.lac)
subscr->lac = mmctx->ra.lac;
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index a0af42bee..83e17dbd4 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -2360,8 +2360,7 @@ void gtphub_resolved_ggsn(struct gtphub *hub, const char *apn_oi_str,
ggsn->peer = pp;
gtphub_port_ref_count_inc(pp);
- strncpy(ggsn->apn_oi_str, apn_oi_str, sizeof(ggsn->apn_oi_str));
- ggsn->apn_oi_str[sizeof(ggsn->apn_oi_str) - 1] = '\0';
+ osmo_strlcpy(ggsn->apn_oi_str, apn_oi_str, sizeof(ggsn->apn_oi_str));
ggsn->expiry_entry.del_cb = resolved_gssn_del_cb;
expiry_add(&hub->expire_slowly, &ggsn->expiry_entry, now);
diff --git a/openbsc/src/gprs/gtphub_ares.c b/openbsc/src/gprs/gtphub_ares.c
index 667013b8b..afeeda657 100644
--- a/openbsc/src/gprs/gtphub_ares.c
+++ b/openbsc/src/gprs/gtphub_ares.c
@@ -121,8 +121,8 @@ static void make_addr_str(struct ggsn_lookup *lookup)
apn_oi_str = osmo_apn_qualify_from_imsi(lookup->imsi_str,
lookup->apn_ni_str,
lookup->have_3dig_mnc);
- strncpy(lookup->apn_oi_str, apn_oi_str, sizeof(lookup->apn_oi_str));
- lookup->apn_oi_str[sizeof(lookup->apn_oi_str)-1] = '\0';
+ osmo_strlcpy(lookup->apn_oi_str, apn_oi_str,
+ sizeof(lookup->apn_oi_str));
}
static int start_ares_query(struct ggsn_lookup *lookup)
@@ -170,11 +170,9 @@ struct gtphub_peer_port *gtphub_resolve_ggsn_addr(struct gtphub *hub,
expiring_item_init(&lookup->expiry_entry);
lookup->hub = hub;
- strncpy(lookup->imsi_str, imsi_str, sizeof(lookup->imsi_str));
- lookup->imsi_str[sizeof(lookup->imsi_str)-1] = '\0';
-
- strncpy(lookup->apn_ni_str, apn_ni_str, sizeof(lookup->apn_ni_str));
- lookup->apn_ni_str[sizeof(lookup->apn_ni_str)-1] = '\0';
+ osmo_strlcpy(lookup->imsi_str, imsi_str, sizeof(lookup->imsi_str));
+ osmo_strlcpy(lookup->apn_ni_str, apn_ni_str,
+ sizeof(lookup->apn_ni_str));
make_addr_str(lookup);
diff --git a/openbsc/src/gprs/sgsn_auth.c b/openbsc/src/gprs/sgsn_auth.c
index 4b69a0d10..1fa7fc4ae 100644
--- a/openbsc/src/gprs/sgsn_auth.c
+++ b/openbsc/src/gprs/sgsn_auth.c
@@ -20,6 +20,7 @@
*/
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
+#include <osmocom/core/utils.h>
#include <openbsc/sgsn.h>
#include <openbsc/gprs_sgsn.h>
#include <openbsc/gprs_gmm.h>
@@ -62,7 +63,7 @@ int sgsn_acl_add(const char *imsi, struct sgsn_config *cfg)
acl = talloc_zero(NULL, struct imsi_acl_entry);
if (!acl)
return -ENOMEM;
- strncpy(acl->imsi, imsi, sizeof(acl->imsi) - 1);
+ osmo_strlcpy(acl->imsi, imsi, sizeof(acl->imsi));
llist_add(&acl->list, &cfg->imsi_acl);