Page MenuHomeFreeBSD

pwd: Clean up and adopt POSIX semantics
ClosedPublic

Authored by des on Fri, Feb 6, 4:29 PM.
Tags
None
Referenced Files
F144925100: D55146.diff
Sat, Feb 14, 4:29 AM
Unknown Object (File)
Thu, Feb 12, 4:09 PM
Unknown Object (File)
Thu, Feb 12, 12:39 PM
Unknown Object (File)
Thu, Feb 12, 12:33 PM
Unknown Object (File)
Thu, Feb 12, 7:05 AM
Unknown Object (File)
Thu, Feb 12, 7:00 AM
Unknown Object (File)
Thu, Feb 12, 6:28 AM
Unknown Object (File)
Thu, Feb 12, 5:30 AM
Subscribers

Details

Summary

According to POSIX, the default should be -L. Based on code history,
whoever first wrote BSD pwd(1) could not figure out how to implement
-L and therefore made -P the default (and only) option. Support for -L
was later added, but the default was never changed.

Clean up the code, make -L the default, and rewrite getcwd_logical() to
reject paths that contain dot or dot-dot, as required by POSIX.

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Fri, Feb 6, 4:29 PM
olce added a subscriber: olce.

(Small point: Last if currently looks slightly weird as it is calling getcwd_physical() even on !physical, would use a logical variable instead of physical.)

This revision is now accepted and ready to land.Fri, Feb 6, 4:56 PM

Why shouldn't we relnotes yes/mfc no/warn everyone for a subtle change in behavior?

bin/pwd/pwd.c
98

Note pwd -? used to say:

pwd: Illegal option -?

Now says:

pwd: illegal option -- ?
usage: pwd [-L | -P]
des marked an inline comment as done.Fri, Feb 6, 5:44 PM
des added inline comments.
bin/pwd/pwd.c
98

Nothing has changed. The first example is from our sh's builtin pwd, the second is from /sbin/pwd.

des marked an inline comment as done.Fri, Feb 6, 5:45 PM

(Small point: Last if currently looks slightly weird as it is calling getcwd_physical() even on !physical, would use a logical variable instead of physical.)

I agree but the diff was starting to look like I was changing code just for the sake of change so I reverted that part...

This revision now requires review to proceed.Fri, Feb 6, 5:49 PM
This revision is now accepted and ready to land.Fri, Feb 6, 9:28 PM

implement dot and dotdot checks

This revision now requires review to proceed.Sat, Feb 7, 10:53 AM
des edited the summary of this revision. (Show Details)
olce requested changes to this revision.Sat, Feb 7, 8:48 PM
olce added inline comments.
bin/pwd/pwd.c
55–56

Detection of .. is wrong (any two-character path component ending with . passes the test).

This revision now requires changes to proceed.Sat, Feb 7, 8:48 PM
des marked an inline comment as done.Sat, Feb 7, 8:59 PM
des added inline comments.
bin/pwd/pwd.c
55–56

No.

des marked an inline comment as done.Sat, Feb 7, 8:59 PM
bin/pwd/pwd.c
55–56

Oh, right.

This form is obscure though. Additionally, it does twice the == '.' test if the first fails, and the second operand of the disjunction increments p for nothing if the second '.' matched.

So I strongly suggest changing that to a logical formula that does not use side-effects and is exactly to the point.

This revision now requires review to proceed.Sat, Feb 7, 11:36 PM
des marked an inline comment as done.Sat, Feb 7, 11:36 PM

Looks fine (with pointed-out test changed).

This revision is now accepted and ready to land.Mon, Feb 9, 8:24 AM
This revision was automatically updated to reflect the committed changes.