[Gluster-devel] glfs_readdir_r is painful

Eric Blake eblake at redhat.com
Wed Oct 30 22:31:50 UTC 2013

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://supercolony.gluster.org/pipermail/gluster-devel/attachments/20131030/4357c474/attachment-0001.sig>

More information about the Gluster-devel mailing list