Re: readlink: be quiet about overlong argument without '-f' option
I feel the same way about this. It can help in deep trees. > On Mon, Sep 04, 2017 at 11:43:56AM -0500, Scott Cheloha wrote: > > Thoughts? > > The PATH_MAX check was introduced in rev 1.10 1997/09/23. That was > after the doumentation, so it might be a mistake that the man page > was not updated. > > The feature worked for 20 years, I see no reason to remove it. > > Personally I prefer to see the error when something goes wrong. > > bluhm > > > Index: usr.bin/readlink/readlink.c > > === > > RCS file: /cvs/src/usr.bin/readlink/readlink.c,v > > retrieving revision 1.27 > > diff -u -p -r1.27 readlink.c > > --- usr.bin/readlink/readlink.c 9 Oct 2015 01:37:08 - 1.27 > > +++ usr.bin/readlink/readlink.c 4 Sep 2017 15:57:47 - > > @@ -64,14 +64,6 @@ main(int argc, char *argv[]) > > if (argc != 1) > > usage(); > > > > - n = strlen(argv[0]); > > - if (n > PATH_MAX - 1) { > > - fprintf(stderr, > > - "readlink: filename longer than PATH_MAX-1 (%d)\n", > > - PATH_MAX - 1); > > - exit(1); > > - } > > - > > if (fflag) { > > if (realpath(argv[0], buf) == NULL) > > err(1, "%s", argv[0]); >
Re: readlink: be quiet about overlong argument without '-f' option
On Mon, Sep 04, 2017 at 11:43:56AM -0500, Scott Cheloha wrote: > Thoughts? The PATH_MAX check was introduced in rev 1.10 1997/09/23. That was after the doumentation, so it might be a mistake that the man page was not updated. The feature worked for 20 years, I see no reason to remove it. Personally I prefer to see the error when something goes wrong. bluhm > Index: usr.bin/readlink/readlink.c > === > RCS file: /cvs/src/usr.bin/readlink/readlink.c,v > retrieving revision 1.27 > diff -u -p -r1.27 readlink.c > --- usr.bin/readlink/readlink.c 9 Oct 2015 01:37:08 - 1.27 > +++ usr.bin/readlink/readlink.c 4 Sep 2017 15:57:47 - > @@ -64,14 +64,6 @@ main(int argc, char *argv[]) > if (argc != 1) > usage(); > > - n = strlen(argv[0]); > - if (n > PATH_MAX - 1) { > - fprintf(stderr, > - "readlink: filename longer than PATH_MAX-1 (%d)\n", > - PATH_MAX - 1); > - exit(1); > - } > - > if (fflag) { > if (realpath(argv[0], buf) == NULL) > err(1, "%s", argv[0]);
readlink: be quiet about overlong argument without '-f' option
Hi, readlink(1) has a check before calling readlink(2) that prints a hand-rolled error message if your argument exceeds (PATH_MAX - 1) bytes. $ readlink $(perl -e 'print "z"x1024') This contradicts the documentation, which says that absent the '-f' flag nothing will be printed if the argument is not a symbolic link. Exceeding (PATH_MAX - 1) bytes definitely excludes your argument, so in that case readlink(1) should just say nothing. With the '-f' option, readlink(1) already complains about an overlong path or path component, so in that case the check is redundant. $ readlink -f $(perl -e 'print "z"x256') Without the '-f' flag this change would put us in sync with GNU readlink's behavior. With the '-f' flag, it puts us in sync with GNU realpath's behavior. CC'd nicm@ because he expressed interest in this a few months back when I submitted it as part of a larger patch that didn't make sense in aggregate. Thoughts? -- Scott Cheloha Index: usr.bin/readlink/readlink.c === RCS file: /cvs/src/usr.bin/readlink/readlink.c,v retrieving revision 1.27 diff -u -p -r1.27 readlink.c --- usr.bin/readlink/readlink.c 9 Oct 2015 01:37:08 - 1.27 +++ usr.bin/readlink/readlink.c 4 Sep 2017 15:57:47 - @@ -64,14 +64,6 @@ main(int argc, char *argv[]) if (argc != 1) usage(); - n = strlen(argv[0]); - if (n > PATH_MAX - 1) { - fprintf(stderr, - "readlink: filename longer than PATH_MAX-1 (%d)\n", - PATH_MAX - 1); - exit(1); - } - if (fflag) { if (realpath(argv[0], buf) == NULL) err(1, "%s", argv[0]);