From: Alejandro Colomar <alx@kernel.org>
To: Helge Kreutzmann <debian@helgefjell.de>
Cc: mario.blaettermann@gmail.com, linux-man@vger.kernel.org
Subject: Re: Issue in man page readlink.2
Date: Wed, 1 Nov 2023 17:33:32 +0100 [thread overview]
Message-ID: <ZUJ93Bo1SOJR-83-@debian> (raw)
In-Reply-To: <ZUJaZIaqGk23UECp@meinfjell.helgefjelltest.de>
[-- Attachment #1: Type: text/plain, Size: 2630 bytes --]
On Wed, Nov 01, 2023 at 02:02:12PM +0000, Helge Kreutzmann wrote:
> Without further ado, the following was found:
>
> Issue: the link target → link target
Fixed:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=1a2af84e62456a6ae29f1a1e1f73d761189065be>
Thanks,
Alex
>
> "#include E<lt>limits.hE<gt>\n"
> "#include E<lt>stdio.hE<gt>\n"
> "#include E<lt>stdlib.hE<gt>\n"
> "#include E<lt>sys/stat.hE<gt>\n"
> "#include E<lt>unistd.hE<gt>\n"
> "\\&\n"
> "int\n"
> "main(int argc, char *argv[])\n"
> "{\n"
> " char *buf;\n"
> " ssize_t nbytes, bufsiz;\n"
> " struct stat sb;\n"
> "\\&\n"
> " if (argc != 2) {\n"
> " fprintf(stderr, \"Usage: %s E<lt>pathnameE<gt>\\en\", argv[0]);\n"
> " exit(EXIT_FAILURE);\n"
> " }\n"
> "\\&\n"
> " if (lstat(argv[1], &sb) == -1) {\n"
> " perror(\"lstat\");\n"
> " exit(EXIT_FAILURE);\n"
> " }\n"
> "\\&\n"
> " /* Add one to the link size, so that we can determine whether\n"
> " the buffer returned by readlink() was truncated. */\n"
> "\\&\n"
> " bufsiz = sb.st_size + 1;\n"
> "\\&\n"
> " /* Some magic symlinks under (for example) /proc and /sys\n"
> " report \\[aq]st_size\\[aq] as zero. In that case, take PATH_MAX as\n"
> " a \"good enough\" estimate. */\n"
> "\\&\n"
> " if (sb.st_size == 0)\n"
> " bufsiz = PATH_MAX;\n"
> "\\&\n"
> " buf = malloc(bufsiz);\n"
> " if (buf == NULL) {\n"
> " perror(\"malloc\");\n"
> " exit(EXIT_FAILURE);\n"
> " }\n"
> "\\&\n"
> " nbytes = readlink(argv[1], buf, bufsiz);\n"
> " if (nbytes == -1) {\n"
> " perror(\"readlink\");\n"
> " exit(EXIT_FAILURE);\n"
> " }\n"
> "\\&\n"
> " /* Print only \\[aq]nbytes\\[aq] of \\[aq]buf\\[aq], as it doesn't contain a terminating\n"
> " null byte (\\[aq]\\e0\\[aq]). */\n"
> " printf(\"\\[aq]%s\\[aq] points to \\[aq]%.*s\\[aq]\\en\", argv[1], (int) nbytes, buf);\n"
> "\\&\n"
> " /* If the return value was equal to the buffer size, then the\n"
> " the link target was larger than expected (perhaps because the\n"
> " target was changed between the call to lstat() and the call to\n"
> " readlink()). Warn the user that the returned target may have\n"
> " been truncated. */\n"
> "\\&\n"
> " if (nbytes == bufsiz)\n"
> " printf(\"(Returned buffer may have been truncated)\\en\");\n"
> "\\&\n"
> " free(buf);\n"
> " exit(EXIT_SUCCESS);\n"
> "}\n"
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2023-11-01 16:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-01 14:02 Issue in man page readlink.2 Helge Kreutzmann
2023-11-01 16:33 ` Alejandro Colomar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZUJ93Bo1SOJR-83-@debian \
--to=alx@kernel.org \
--cc=debian@helgefjell.de \
--cc=linux-man@vger.kernel.org \
--cc=mario.blaettermann@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).