Thread (15 messages) 15 messages, 4 authors, 2013-03-08

RE: [PATCH] net/rds: using strlcpy instead of strncpy

From: David Laight <hidden>
Date: 2013-02-28 09:42:51

quoted hunk ↗ jump to hunk
  when src strlen is sizeof(ctr.name) - 1, the dest str is not '\0' end.
  better use strlcpy instead.

Signed-off-by: Chen Gang <redacted>
---
 net/rds/stats.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/net/rds/stats.c b/net/rds/stats.c
index 7be790d..b9ac1df 100644
--- a/net/rds/stats.c
+++ b/net/rds/stats.c
@@ -86,7 +86,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);
+		strlcpy(ctr.name, names[i], sizeof(ctr.name));
 		ctr.value = values[i];
If the target buffer ends up being copied to userspace that
might lead to random kernel memory being leaked.

	David
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help