[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gluster-devel] glfs_readdir_r is painful
From: |
Eric Blake |
Subject: |
Re: [Gluster-devel] glfs_readdir_r is painful |
Date: |
Wed, 30 Oct 2013 16:31:50 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
On 10/30/2013 04:08 PM, Anand Avati wrote:
> Eric,
> Thanks for the insights. I have posted a patch at
> http://review.gluster.org/6201 which clarifies the usage of
> glfs_readdir_r() and also introduce glfs_readdir().
Thanks for starting that. I see an off-by-one in that patch; pre-patch
you did:
strncpy (dirent->d_name, gf_dirent->d_name, 256);
but post-patch, you have:
strncpy (dirent->d_name, gf_dirent->d_name, GF_NAME_MAX);
with GF_NAME_MAX set to either NAME_MAX or 255. This is a bug; you MUST
strncpy at least 1 byte more than the maximum name if you are to
guarantee a NUL-terminated d_name for the user.
Oh, and NAME_MAX is not guaranteed to be defined as 255; if it is larger
than 255 you are wasting memory compared to XFS, if it is less than 255
[although unlikely], you have made it impossible to return valid file
names to the user. You may be better off just hard-coding GF_NAME_MAX
to 255 regardless of what the system has for its NAME_MAX.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature