Skip to content

ls: no separator between permissions and link count #11789

@egmontkob

Description

@egmontkob

From #10980 (comment) onwards:


Create 10 files /tmp/z/{a,b,c,d,e,f,g} and /tmp/y/{o,p,q}. All with ACLs.

Standing in /tmp/y execute ls -l /tmp/z.

Notice no separator at all between the permissions and the link counts.

strace the program. Notice it calls listxattr() for files a, b ... g with no path prepended, i.e. relative to the current directory which is /tmp/y. They are not found.

When checking if there's a need for an additional column, it iterates through the filenames of /tmp/z (the directory being listed), but incorrectly checks for the ACLs of those files under the current directory (/tmp/y).


Why does the code listxattr() the files twice?

For the regular fields, it doesn't statx() them twice. Only once, and remembers the results that it later formats nicely. That's what it should do with the ACLs, too.

Even if the base directory bug got fixed, listxattr()ing twice (once for measuring the width and once for printing the actual values) would still presumably contain a race condition.

If none of the files has an ACL during the first round, but some of them already have ACLs during the second round then (I presume based on the findings so far, haven't verified though) the column width wouldn't be increased, yet a + sign would get printed in its column, resulting in no separator between the two columns (as it can already be seen sometimes, due to the faulty base directory). This, in turn, can break scripts that parse the output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions