summaryrefslogtreecommitdiff
path: root/genl_family.c
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2022-05-23 21:02:38 +0200
committerrofl0r <rofl0r@users.noreply.github.com>2022-09-16 01:34:26 +0000
commitca1c7757d884f8eaaf039282a98dc852427f4e2e (patch)
tree69bfd0338dc51d5ef0733f7d7fc18408599db840 /genl_family.c
parent46f0acba8141c8d49a8b2358f6436779e486d150 (diff)
downloadlibnl-tiny-ca1c7757d884f8eaaf039282a98dc852427f4e2e.tar.gz
genl_family: explicitly null terminate strncpy destination buffer
The strncpy() function doesn't null terminate the destination string if the source string is at least as long as the destination. (This behavior is defined by the C99 specification.) As a result, the destination string must be null terminated after calling strncpy(). And clang11 static analyzer thus reports following: genl_family.c:148:2: error: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 15 [-Werror=stringop-truncation] 148 | strncpy(grp->name, name, GENL_NAMSIZ - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ References: https://gitlab.com/openwrt/project/libnl-tiny/-/jobs/2495301251#L197 Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'genl_family.c')
-rw-r--r--genl_family.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/genl_family.c b/genl_family.c
index 221acfa..a0d83dc 100644
--- a/genl_family.c
+++ b/genl_family.c
@@ -146,6 +146,7 @@ int genl_family_add_grp(struct genl_family *family, uint32_t id,
grp->id = id;
strncpy(grp->name, name, GENL_NAMSIZ - 1);
+ grp->name[GENL_NAMSIZ - 1] = '\0';
nl_list_add_tail(&grp->list, &family->gf_mc_grps);