From fa391ee86ce0df7e0b637410bd07664b44b1adba Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 26 Jul 2018 20:15:51 +0200 Subject: [PATCH] vlr_access_req_fsm.c: use osmo_strlcpy and avoid compiler error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc 8.1.0: ../../../../src/osmo-msc/src/libvlr/vlr_access_req_fsm.c:679:3: error: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 31 [-Werror=stringop-truncation] strncpy(par->imsi, mi_string, sizeof(par->imsi)-1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The Mobile Identity is a union of various kinds, but the IMSI is at most 15 digits, so truncation is "intended". I hope other layers validate the correct length of an IMSI MI. Change-Id: I0a17a188fc91e42e252ae4bf1d6cd0bf0e5eb077 --- src/libvlr/vlr_access_req_fsm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libvlr/vlr_access_req_fsm.c b/src/libvlr/vlr_access_req_fsm.c index 79eb75f85..3a0760d84 100644 --- a/src/libvlr/vlr_access_req_fsm.c +++ b/src/libvlr/vlr_access_req_fsm.c @@ -676,8 +676,7 @@ vlr_proc_acc_req(struct osmo_fsm_inst *parent, mi_type = mi_lv[1] & GSM_MI_TYPE_MASK; switch (mi_type) { case GSM_MI_TYPE_IMSI: - strncpy(par->imsi, mi_string, sizeof(par->imsi)-1); - par->imsi[sizeof(par->imsi)-1] = '\0'; + osmo_strlcpy(par->imsi, mi_string, sizeof(par->imsi)); par->by_tmsi = false; break; case GSM_MI_TYPE_TMSI: