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 -0000 1.27 +++ usr.bin/readlink/readlink.c 4 Sep 2017 15:57:47 -0000 @@ -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]);