genl_family: explicitly null terminate strncpy destination buffer staging/ynezz/fix-strncpy
authorPetr Štetiar <ynezz@true.cz>
Mon, 23 May 2022 19:02:38 +0000 (21:02 +0200)
committerPetr Štetiar <ynezz@true.cz>
Mon, 23 May 2022 19:02:38 +0000 (21:02 +0200)
commit28c44ca97cd546ef8168e7476472a0da022b3421
treee32c2188a47e0673107eeafcd1f3d0fb845ff74c
parentc42d890625f5b1c6986b0545775d50cf20c7a717
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>
genl_family.c
include/netlink/genl/family.h