gfapi: fix potential non-0-terminated string (CID 1134002)

Use correct target buffer length for strncpy and make
sure that the target string is 0 terminated.

Fixes Coverity ID 1134002.

Change-Id: I97a74a94a818eb08a711e547f2ac6ae46087f065
BUG: 789278
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-on: http://review.gluster.org/10247
Tested-by: NetBSD Build System
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kotresh HR <khiremat@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Michael Adam 2015-04-15 09:15:23 +02:00 committed by Niels de Vos
parent 7fb85e3670
commit fc451b5b0f

View File

@ -2062,7 +2062,8 @@ gf_dirent_to_dirent (gf_dirent_t *gf_dirent, struct dirent *dirent)
dirent->d_namlen = strlen (gf_dirent->d_name);
#endif
strncpy (dirent->d_name, gf_dirent->d_name, GF_NAME_MAX + 1);
strncpy (dirent->d_name, gf_dirent->d_name, NAME_MAX);
dirent->d_name[NAME_MAX] = 0;
}