From 64a2627cc1cfb8cc547c160c2362d05401b8ed87 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 4 Jun 2012 16:41:17 +0200 Subject: bdb: fix erroneous strncpy in file name construction Using strncpy like that fails to copy the trailing NUL byte of dirent->d_name, which is required, since the result buffer, entry_path is stat'ed in the code just below. Besides, there is no need for strncpy, since we know the source buffer will fit in the possibly-just-realloc'd destination buffer: use memcpy and +1 to include the trailing NUL. Change-Id: I4d4cfb5b7df3c018516919f2d67c21c07de126cb BUG: 789278 Signed-off-by: Jim Meyering Reviewed-on: http://review.gluster.com/3588 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/storage/bdb/src/bdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'xlators/storage') diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c index 1a5ef02b..384094b5 100644 --- a/xlators/storage/bdb/src/bdb.c +++ b/xlators/storage/bdb/src/bdb.c @@ -1360,8 +1360,8 @@ dir_read: } } - strncpy (&entry_path[real_path_len+1], dirent->d_name, - tmp_name_len); + memcpy (&entry_path[real_path_len+1], dirent->d_name, + tmp_name_len + 1); op_ret = stat (entry_path, &buf); if (op_ret < 0) { op_errno = errno; -- cgit