From: Douglas Bagnall Date: Thu, 9 Feb 2017 00:02:52 +0000 (+1300) Subject: shadow_copy_get_shadow_copy_data: fix GCC snprintf warning X-Git-Tag: talloc-2.1.9~213 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a091a30a5bd50bc02df3e9c01b11f70c94dbd053;p=thirdparty%2Fsamba.git shadow_copy_get_shadow_copy_data: fix GCC snprintf warning GCC 7 warns about snprintf truncating a dirent d_name (potentially 255 bytes) to 25 bytes, even though we have checked that it is 25 long in shadow_copy_match_name(). Using strlcpy instead of snprintf lets us check it again, JUST TO BE SURE. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/source3/include/ntioctl.h b/source3/include/ntioctl.h index f9e6dd996a7..bd80a30d34a 100644 --- a/source3/include/ntioctl.h +++ b/source3/include/ntioctl.h @@ -30,7 +30,7 @@ /* For FSCTL_GET_SHADOW_COPY_DATA ...*/ -typedef char SHADOW_COPY_LABEL[25]; +typedef char SHADOW_COPY_LABEL[25]; /* sizeof("@GMT-2004.02.18-15.44.00") + 1 */ struct shadow_copy_data { /* Total number of shadow volumes currently mounted */ diff --git a/source3/modules/vfs_shadow_copy.c b/source3/modules/vfs_shadow_copy.c index 9b43e85af63..dae70f555e5 100644 --- a/source3/modules/vfs_shadow_copy.c +++ b/source3/modules/vfs_shadow_copy.c @@ -252,6 +252,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, while (True) { SHADOW_COPY_LABEL *tlabels; struct dirent *d; + int ret; d = SMB_VFS_NEXT_READDIR(handle, p, NULL); if (d == NULL) { @@ -280,7 +281,15 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, return -1; } - snprintf(tlabels[shadow_copy_data->num_volumes++], sizeof(*tlabels), "%s",d->d_name); + ret = strlcpy(tlabels[shadow_copy_data->num_volumes], d->d_name, + sizeof(tlabels[shadow_copy_data->num_volumes])); + if (ret != sizeof(tlabels[shadow_copy_data->num_volumes]) - 1) { + DEBUG(0,("shadow_copy_get_shadow_copy_data: malformed label %s\n", + d->d_name)); + SMB_VFS_NEXT_CLOSEDIR(handle, p); + return -1; + } + shadow_copy_data->num_volumes++; shadow_copy_data->labels = tlabels; }