diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-01-13 03:12:08 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-01-23 11:59:01 +0000 |
commit | 93bafb611a58293e0353320a14db298133c9d99a (patch) | |
tree | 4ba6d276b7f5e2fda43f21b765d7cca8c6b00d5e /openbsc/tests | |
parent | 59504dc80fe8c0d9a18994d82586a550c7efa341 (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/tests')
-rw-r--r-- | openbsc/tests/gtphub/gtphub_test.c | 24 | ||||
-rw-r--r-- | openbsc/tests/sgsn/sgsn_test.c | 6 |
2 files changed, 12 insertions, 18 deletions
diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c index 2b542ddf8..e7c27d2cb 100644 --- a/openbsc/tests/gtphub/gtphub_test.c +++ b/openbsc/tests/gtphub/gtphub_test.c @@ -437,21 +437,15 @@ struct gtphub_peer_port *__wrap_gtphub_resolve_ggsn_addr(struct gtphub *hub, " returning GGSN addr from imsi %s ni %s: %s\n", imsi_str, apn_ni_str, gtphub_port_str(pp)); - if (imsi_str) { - strncpy(resolve_ggsn_got_imsi, imsi_str, - sizeof(resolve_ggsn_got_imsi)); - resolve_ggsn_got_imsi[sizeof(resolve_ggsn_got_imsi) - 1] = '\0'; - } - else - strcpy(resolve_ggsn_got_imsi, "(null)"); - - if (apn_ni_str) { - strncpy(resolve_ggsn_got_ni, apn_ni_str, - sizeof(resolve_ggsn_got_ni)); - resolve_ggsn_got_ni[sizeof(resolve_ggsn_got_ni) - 1] = '\0'; - } - else - strcpy(resolve_ggsn_got_ni, "(null)"); + if (!imsi_str) + imsi_str = "(null)"; + osmo_strlcpy(resolve_ggsn_got_imsi, imsi_str, + sizeof(resolve_ggsn_got_imsi)); + + if (!apn_ni_str) + apn_ni_str = "(null)"; + osmo_strlcpy(resolve_ggsn_got_ni, apn_ni_str, + sizeof(resolve_ggsn_got_ni)); return pp; } diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index fea635e9b..e1fd2e713 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -2248,7 +2248,7 @@ static void test_ggsn_selection(void) /* Create a context */ OSMO_ASSERT(count(gprs_llme_list()) == 0); ctx = alloc_mm_ctx(local_tlli, &raid); - strncpy(ctx->imsi, imsi1, sizeof(ctx->imsi) - 1); + osmo_strlcpy(ctx->imsi, imsi1, sizeof(ctx->imsi)); /* Allocate and attach a subscriber */ s1 = gprs_subscr_get_or_create_by_mmctx(ctx); @@ -2273,7 +2273,7 @@ static void test_ggsn_selection(void) pdp_data = sgsn_subscriber_pdp_data_alloc(s1->sgsn_data); pdp_data->context_id = 1; pdp_data->pdp_type = 0x0121; - strncpy(pdp_data->apn_str, "*", sizeof(pdp_data->apn_str)-1); + osmo_strlcpy(pdp_data->apn_str, "*", sizeof(pdp_data->apn_str)); /* Resolve GGSNs */ @@ -2326,7 +2326,7 @@ static void test_ggsn_selection(void) /* Add PDP data entry to subscriber */ - strncpy(pdp_data->apn_str, "Test.Apn", sizeof(pdp_data->apn_str)-1); + osmo_strlcpy(pdp_data->apn_str, "Test.Apn", sizeof(pdp_data->apn_str)); tp.lv[GSM48_IE_GSM_APN].len = gprs_str_to_apn(apn_enc, sizeof(apn_enc), "Test.Apn"); |