On 06/30/2016 05:38 PM, Zdenek Kabelac wrote:

Cut & paste example code solution from lvm2:

#if !defined(__GLIBC__) || (__GLIBC__ < 2) || ((__GLIBC__ == 2) &&
(__GLIBC_MINOR__ < 23))
    /* readdir_r is deprecated with newer GLIBC */
    struct dirent entry, *iter = 0;
    while ( (errno = readdir_r( d.d, &entry, &iter )) == 0 && iter ) {
        std::string ename( entry.d_name );
#else
    struct dirent *entry;
    errno = 0;
    while ( (entry = readdir( d.d )) ) {
        std::string ename( entry->d_name );
#endif

Why not use readdir unconditionally?

The point of the deprecation was that readdir is much more portable than readir_r. Stack allocation of struct dirent is not supported; the above has a buffer overflow in the d_name field on many systems.

Florian
--
devel mailing list
devel@lists.fedoraproject.org
https://lists.fedoraproject.org/admin/lists/devel@lists.fedoraproject.org

Reply via email to