Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANfL31zzE0rJFGJMFC8UZ64cUiriQ6-99QRN1zC0crYtmmpoow@mail.gmail.com>
Date: Wed, 3 Dec 2025 13:04:05 +0530
From: Neeraj Sharma <neerajsharma.live@...il.com>
To: musl@...ts.openwall.com
Subject: Re: Potential bug in musl in nftw implementation

On Wed, Dec 3, 2025 at 11:21 AM Neeraj Sharma
<neerajsharma.live@...il.com> wrote:
>
> While evaluating fil-c [1], I noticed a strange issue with a sample C code to list folders and files with sizes (code enclosed below). I used fil-c [1]  with musl, but compared the output with stock clang-17, gcc and noticed a difference in output on my system. After much investigation and validation I have come to realize a potential issue with musl nftw implementation. I have not come around finding the actual issue, but reporting this nonetheless in case someone else knows about this or is facing similar issues.
>

I have identified a bug in nftw.c implementation within musl. At least
to the extent I understand the functionality of nftw as described
within https://linux.die.net/man/3/nftw

Line 74 in `musl-1.2.5.orig/src/misc/nftw.c` is the issue. It closes
the file descriptor and leaves it there. Irrespective continuing
further without any other action seems incorrect anyways. This means
that further folder traversal is not done. I confirmed this analysis
by increasing the value of fd_limit in my calling code (dirworth.c)
and this time around the undiscovered file earlier was now discovered.

```
 70     if (type == FTW_D || type == FTW_DP) {
 71         dfd = open(path, O_RDONLY);
 72         err = errno;
 73         if (dfd < 0 && err == EACCES) type = FTW_DNR;
 74         if (!fd_limit) close(dfd);
 75     }
```

Modified dirworth.c code which worked for my folder depth.

```c
// this works because my fd_limit is higher, which was earlier 10
nftw(dirpath, process_entry, 20, FTW_PHYS | FTW_DEPTH
```

Regards,
Neeraj

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.