|
From: | Anand Avati |
Subject: | Re: [Gluster-devel] glfs_readdir_r is painful |
Date: | Wed, 30 Oct 2013 15:37:09 -0700 |
On 10/30/2013 04:08 PM, Anand Avati wrote:Thanks for starting that. I see an off-by-one in that patch; pre-patch
> 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().
you did:
but post-patch, you have:
strncpy (dirent->d_name, gf_dirent->d_name, 256);
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.
[Prev in Thread] | Current Thread | [Next in Thread] |