linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonny Grant <jg@jguk.org>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>,
	linux-man <linux-man@vger.kernel.org>
Subject: Re: readlink
Date: Sat, 2 Jan 2021 21:15:33 +0000	[thread overview]
Message-ID: <daa49f83-22c7-7c62-b318-e00f23e56af4@jguk.org> (raw)
In-Reply-To: <63d3bfdc-93dd-6f3e-8ed4-7036b01f9751@gmail.com>



On 30/12/2020 13:56, Michael Kerrisk (man-pages) wrote:
> Hello Jonny,
> 
> On 12/24/20 6:52 PM, Jonny Grant wrote:
>> Seasons greetings Michael,
>>
>> May I ask, could readlink be updated to use the same wording for null
>> termination like on sprintf, scanf etc?
>>
>> https://man7.org/linux/man-pages/man2/readlink.2.html
>>
>> It says:
>>  "readlink() does not append a null byte to buf"
>>
>> Perhaps it should say:
>>  "readlink() does not append a terminating null byte to buf ('\0')"
>>
>> In addition, is it worth adding a BUGS section to remind that there
>> is no terminating null byte?
>>
>> "readlink() assumes the caller understands that no terminating null
>> byte ('\0') will be written in the provided buf. If the caller didn't
>> memset the buffer to ('\0') or allocate an extra byte for the
>> terminating null byte, there is a risk the caller could overrun the
>> end of the buffer, or use uninitialised values in the buf."
> 
>>
>> Finally, perhaps also the EXAMPLES program could be updated to clarify this:
>>
>> "/* print only nbytes of buf, as it doesn't contain a terminating null byte ('\0') */
>> printf("'%s' points to '%.*s'\n", argv[1], (int) nbytes, buf);
>> "
> 
> I think that having (1) the existing statement at the start of the 
> DESCRIPTION, (2) adding a comment to the code, and (3) adding a BUGS
> section all to cover the same point seems a little excessive.
> I've gone for 2 out of 3.
> 
> Thanks,
> 
> Michael
> 
> --- a/man2/readlink.2
> +++ b/man2/readlink.2
> @@ -93,7 +93,7 @@ in the buffer
>  which has size
>  .IR bufsiz .
>  .BR readlink ()
> -does not append a null byte to
> +does not append a terminating null byte to
>  .IR buf .
>  It will (silently) truncate the contents (to a length of
>  .I bufsiz
> @@ -332,6 +332,8 @@ main(int argc, char *argv[])
>          exit(EXIT_FAILURE);
>      }
>  
> +    /* Print only \(aqnbytes\(aq of \(aqbuf\(aq, as it doesn't contain a terminating
> +       null byte (\(aq\e0\(aq). */
>      printf("\(aq%s\(aq points to \(aq%.*s\(aq\en", argv[1], (int) nbytes, buf);
>  
>      /* If the return value was equal to the buffer size, then the
> 
> 

Looks good, thank you.
Jonny

      reply	other threads:[~2021-01-02 21:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-24 17:52 readlink Jonny Grant
2020-12-30 13:56 ` readlink Michael Kerrisk (man-pages)
2021-01-02 21:15   ` Jonny Grant [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=daa49f83-22c7-7c62-b318-e00f23e56af4@jguk.org \
    --to=jg@jguk.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@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 NNTP newsgroup(s).