Skip to content

Commit

Permalink
net/rds: zero last byte for strncpy
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chen Gang authored and David S. Miller committed Mar 8, 2013
1 parent d916932 commit 2e85d67
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/rds/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void rds_stats_info_copy(struct rds_info_iterator *iter,
for (i = 0; i < nr; i++) {
BUG_ON(strlen(names[i]) >= sizeof(ctr.name));
strncpy(ctr.name, names[i], sizeof(ctr.name) - 1);
ctr.name[sizeof(ctr.name) - 1] = '\0';
ctr.value = values[i];

rds_info_copy(iter, &ctr, sizeof(ctr));
Expand Down

0 comments on commit 2e85d67

Please sign in to comment.