Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net/rds: zero last byte for strncpy

for NUL terminated string, need be always sure '\0' in the end.

additional info:
strncpy will pads with zeroes to the end of the given buffer.
should initialise every bit of memory that is going to be copied to userland

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Chen Gang and committed by
David S. Miller
2e85d676 d9169323

+1
+1
net/rds/stats.c
··· 87 87 for (i = 0; i < nr; i++) { 88 88 BUG_ON(strlen(names[i]) >= sizeof(ctr.name)); 89 89 strncpy(ctr.name, names[i], sizeof(ctr.name) - 1); 90 + ctr.name[sizeof(ctr.name) - 1] = '\0'; 90 91 ctr.value = values[i]; 91 92 92 93 rds_info_copy(iter, &ctr, sizeof(ctr));