unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: libc-alpha@sourceware.org,
	 Samuel Thibault <samuel.thibault@ens-lyon.org>
Subject: Re: [PATCH 1/3] <fd_to_filename.h>: Add type safety and port to Hurd
Date: Sat, 15 Feb 2020 14:16:52 +0100	[thread overview]
Message-ID: <87wo8oxa63.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <61b49643-9c7b-7060-6eb7-21060dd6e22f@cs.ucla.edu> (Paul Eggert's message of "Fri, 14 Feb 2020 12:28:52 -0800")

* Paul Eggert:

> On 2/14/20 10:11 AM, Florian Weimer wrote:
>> +  /* A positive int value has at most 10 decimal digits.  */
>> +  char buffer[sizeof (FD_TO_FILENAME_PREFIX) + 10];
>
> This should use 'INT_STRLEN_BOUND (int)' rather than '10', where
> INT_STRLEN_BOUND is taken from intprops.h. Then you don't need the
> comment (and the code won't break on future ILP64 platforms :-).

But INT_STRLEN_BOUND is 11, right?

>> +char *
>> +__fd_to_filename (int descriptor, struct fd_to_filename *storage)
>> +{
>> +  char *p = mempcpy (storage->buffer, FD_TO_FILENAME_PREFIX,
>> +                     strlen (FD_TO_FILENAME_PREFIX));
>> +  if (__glibc_likely (descriptor >= 0))
>> +    {
>> +      if (descriptor < 1000)
>> +        p = digit123 (p, descriptor);
>> +      else if (descriptor < 1000 * 1000) ...
>
> It's not clear what that "descriptor >= 0" test is doing. I assume
> that a precondition is that DESCRIPTOR is nonnegative; if so, this
> should be mentioned and the test removed. If it's not a precondition,
> the code should do the right thing if DESCRIPTOR is negative (I
> suppose, return a filename that cannot be opened, though it doesn't do
> that currently) -- which should also be documented but I think this'd
> be overkill.

The problem is when an application passes an invalid descriptor to some
libc function and that ends up with __fd_to_filename.  We should not
make matters worse in that case.

Maybe we should use an assert?

Thanks,
Florian


  reply	other threads:[~2020-02-15 13:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 18:10 [PATCH 0/3] <fd_to_filename.h> improvements Florian Weimer
2020-02-14 18:11 ` [PATCH 1/3] <fd_to_filename.h>: Add type safety and port to Hurd Florian Weimer
2020-02-14 18:43   ` Samuel Thibault
2020-02-14 19:08   ` Adhemerval Zanella
2020-02-14 20:21     ` Florian Weimer
2020-02-14 20:28   ` Paul Eggert
2020-02-15 13:16     ` Florian Weimer [this message]
2020-02-16  0:02       ` Paul Eggert
2020-02-17 15:18         ` Florian Weimer
2020-02-17 18:26           ` Paul Eggert
2020-02-17 18:59             ` Adhemerval Zanella
2020-02-17 19:14               ` Paul Eggert
2020-02-14 18:11 ` [PATCH 2/3] Linux: Port ttyname, ttyname_r to <fd_file_name.h> Florian Weimer
2020-02-14 18:11 ` [PATCH 3/3] Linux: Port fexecve to <fd_to_filename.h> Florian Weimer

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wo8oxa63.fsf@oldenburg2.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@sourceware.org \
    --cc=samuel.thibault@ens-lyon.org \
    /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).