Date: Tue, 12 Jul 2016 11:41:40 +0200 From: Joakim Sindholt <opensource@...sha.com> To: musl@...ts.openwall.com Subject: Re: nftw miscalculates FTW.base when pathnames end in / On Sat, May 14, 2016 at 5:01 AM, Rich Felker <dalias@...c.org> wrote: > lev.base is computed separately depending on whether or not there's a > previous history; for the no-history case, it should be computed by > skipping all trailing slashes, then backing up until the previous > slash or beginning of string, whichever is hit first. But rather than > special-casing !h in do_nftw, the top-level nftw function should > probably set up a fake "-1 level" history structure to pass in. This > gathers the special top-level logic all in one place. I had a look at copying the entire path over and adjusting the first .base accordingly. The problem then became that the root dir would come out as being named something////// depending on how many slashed I added. This runs counter to the glibc behavior which also just hacks off the slashes. In the end I think it's cleaner to just remove trailing slashes than to have them included in all but the root dir. As per your recommendation I also set up a fake -1 history level and removed the special casing for !h, but I'm unsure what default values should be used for dev and ino. Then, as we talked about on IRC, I tried to reduce the stack usage of do_nftw, which was 296 B when all was said and done. By moving a lot of the context stuff explicitly into nftw it got all the way down to 88 on clang and 104 on gcc. Depending on a few minor details those two numbers would switch around. I'm not sure why. In any case it's a third of what it was and I would consider that a substantial win. The code isn't exactly beautiful though. View attachment "0002-optimize-nftw-for-stack-usage.patch" of type "text/x-patch" (4930 bytes) View attachment "0001-ignore-trailing-slashes-in-nftw-path.patch" of type "text/x-patch" (2036 bytes)
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.