public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Martin Sebor <msebor@gmail.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	libstdc++@gcc.gnu.org,        gcc-patches@gcc.gnu.org
Subject: Re: [patch] libstdc++/67747 Allocate space for dirent::d_name
Date: Fri, 02 Oct 2015 17:01:00 -0000	[thread overview]
Message-ID: <20151002170142.GU12094@redhat.com> (raw)
In-Reply-To: <560EB776.2090504@gmail.com>

On 02/10/15 10:57 -0600, Martin Sebor wrote:
>On 10/02/2015 06:34 AM, Jonathan Wakely wrote:
>>On 02/10/15 14:16 +0200, Florian Weimer wrote:
>>>On 09/29/2015 01:37 PM, Jonathan Wakely wrote:
>>>>POSIX says that dirent::d_name has an unspecified length, so calls to
>>>>readdir_r must pass a buffer with enough trailing space for
>>>>{NAME_MAX}+1 characters. I wasn't doing that, which works OK on
>>>>GNU/Linux and BSD where d_name is a large array, but fails on Solaris
>>>>32-bit.
>>>>
>>>>This uses pathconf to get NAME_MAX and allocates a buffer.
>>>
>>>This still has a buffer overflow on certain file systems.
>>>
>>>You must not use readdir_r, it is deprecated and always insecure.  We
>>>should probably mark it as such in the glibc headers.
>>
>>OK, I'll just use readdir() then. The directory stream is private to
>>the library type, so the only way to call readdir() concurrently on a
>>single directory stream is to increment iterators concurrently, which
>>is undefined anyway.
>>
>>So that will work as long as readdir() doesn't use a global static
>>buffer shared between streams, i.e. it meets the POSIX requirement
>>that "They shall not be affected by a call to readdir() on a different
>>directory stream." I don't know if mingw meets that, but there is lots
>>of work needed to make this stuff work in mingw.
>
>Readdir isn't required to be thread-safe (it may reference global
>data) so calling it in multiple threads even with a different dirp
>argument is undefined. A thread-unsafe implementation can meet the
>POSIX requirement and still access global data but without locking.
>
>The Solaris implementation, for example, is explicitly documented
>as thread unsafe.

At this point I think I'm just going to disable the filesystem lib on
Solaris!

  reply	other threads:[~2015-10-02 17:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 12:00 Jonathan Wakely
2015-09-29 19:49 ` Martin Sebor
2015-09-30 12:00   ` Jonathan Wakely
2015-09-30 15:54     ` Martin Sebor
2015-10-01 17:23       ` Jonathan Wakely
2015-10-01 18:38         ` Jonathan Wakely
2015-10-01 23:43           ` Jonathan Wakely
2015-10-01 22:56   ` Martin Sebor
2015-10-02 12:16 ` Florian Weimer
2015-10-02 12:34   ` Jonathan Wakely
2015-10-02 12:41     ` Florian Weimer
2015-10-02 16:34       ` Jonathan Wakely
2015-10-02 16:57     ` Martin Sebor
2015-10-02 17:01       ` Jonathan Wakely [this message]
2015-10-02 17:09       ` Florian Weimer
2015-10-02 17:38         ` Martin Sebor
2015-10-02 17:43           ` Florian Weimer
2015-10-02 17:53             ` Martin Sebor
2015-10-02 18:03               ` Florian Weimer
2015-10-02 12:37   ` Sebastian Huber
2015-10-02 12:52     ` 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

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

  git send-email \
    --in-reply-to=20151002170142.GU12094@redhat.com \
    --to=jwakely@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=msebor@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).