summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-08-08 10:16:54 +0200
committerThomas Haller <thaller@redhat.com>2019-08-08 17:01:21 +0200
commitf6f163d68e756d7ee69b93b0ccb4ab24f9764f77 (patch)
tree1224640275eb07207a8a8765ce4ffa26dfbc94bc /lib
parentfbf831fe474abc9d3c3880d22452bdfa2b3ddd81 (diff)
downloadlibnl-f6f163d68e756d7ee69b93b0ccb4ab24f9764f77.tar.gz
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);
Diffstat (limited to 'lib')
-rw-r--r--lib/route/cls/ematch/text.c1
-rw-r--r--lib/xfrm/sa.c1
2 files changed, 2 insertions, 0 deletions
diff --git a/lib/route/cls/ematch/text.c b/lib/route/cls/ematch/text.c
index b14c4abb..12a1e747 100644
--- a/lib/route/cls/ematch/text.c
+++ b/lib/route/cls/ematch/text.c
@@ -92,6 +92,7 @@ void rtnl_ematch_text_set_algo(struct rtnl_ematch *e, const char *algo)
struct text_data *t = rtnl_ematch_data(e);
strncpy(t->cfg.algo, algo, sizeof(t->cfg.algo));
+ t->cfg.algo[sizeof(t->cfg.algo) - 1] = '\0';
}
char *rtnl_ematch_text_get_algo(struct rtnl_ematch *e)
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) {