problem with errno in readdir64_r() and readdir_r()

Kövesdi György kgy at teledigit.hu
Wed Mar 25 08:49:15 UTC 2009


Hi,

I found that the above mentioned functions can return with strange error 
values in some cases: it is possible to return the previous value of 
the 'errno' without modifying it.
e.g. the 'svn' executable reports strange errors due to this bug.

Those functions contain this code:

bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes <= 0) {
    *result = NULL;
    ret = (bytes==0)? 0 : errno;
    goto all_done;
...

AFAIK the functions __getdents64() and __getdents() return zero at the end of 
the directory, and the 'errno' is not modified in this case (because it is 
not an error), so the previous value of 'errno' can be returned by these 
functions.
I suggest a modification:

bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes == 0) {
    *result = NULL;
    ret = 0;
    goto all_done;
} else if (bytes < 0) {
    *result = NULL;
    ret = (bytes==0)? 0 : errno;
    goto all_done;
...

or something similar. I did not test it, because it is too complicated for me 
to recompile the whole uClibc. It is just an idea.

Regards
K. Gy.


More information about the uClibc mailing list