From f6f163d68e756d7ee69b93b0ccb4ab24f9764f77 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Aug 2019 10:16:54 +0200 Subject: route: fix strncpy() warning from coverity about unterminated string Coverity says: Error: BUFFER_SIZE_WARNING (CWE-120): [#def1] libnl-3.4.0/lib/route/cls/ematch/text.c:94: buffer_size_warning: Calling strncpy with a maximum size argument of 16 bytes on destination array "t->cfg.algo" of size 16 bytes might leave the destination string unterminated. # 92| struct text_data *t = rtnl_ematch_data(e); # 93| # 94|-> strncpy(t->cfg.algo, algo, sizeof(t->cfg.algo)); # 95| } # 96| Error: BUFFER_SIZE_WARNING (CWE-120): [#def11] libnl-3.4.0/lib/xfrm/sa.c:1192: buffer_size_warning: Calling strncpy with a maximum size argument of 64 bytes on destination array "auth->alg_name" of size 64 bytes might leave the destination string unterminated. # 1190| } # 1191| # 1192|-> strncpy(auth->alg_name, tmpl->auth->alg_name, sizeof(auth->alg_name)); # 1193| auth->alg_key_len = tmpl->auth->alg_key_len; # 1194| memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8); --- lib/xfrm/sa.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/xfrm') diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c index 995df9fd..15a3661a 100644 --- a/lib/xfrm/sa.c +++ b/lib/xfrm/sa.c @@ -1190,6 +1190,7 @@ static int build_xfrm_sa_message(struct xfrmnl_sa *tmpl, int cmd, int flags, str } strncpy(auth->alg_name, tmpl->auth->alg_name, sizeof(auth->alg_name)); + auth->alg_name[sizeof(auth->alg_name) - 1] = '\0'; auth->alg_key_len = tmpl->auth->alg_key_len; memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8); if (nla_put(msg, XFRMA_ALG_AUTH, len, auth) < 0) { -- cgit v1.2.3