This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Re: fix off-by-one in dup2
- From: Christopher Faylor <cgf-use-the-mailinglist-please at cygwin dot com>
- To: cygwin-patches at cygwin dot com
- Date: Wed, 4 Dec 2013 12:51:08 -0500
- Subject: Re: fix off-by-one in dup2
- Authentication-results: sourceware.org; auth=none
- References: <52437121 dot 1070507 at redhat dot com> <20131204093238 dot GA28314 at calimero dot vinschen dot de> <20131204113626 dot GB29444 at calimero dot vinschen dot de> <20131204120408 dot GC29444 at calimero dot vinschen dot de> <20131204170028 dot GA2590 at ednor dot casa dot cgf dot cx> <20131204172324 dot GA13448 at calimero dot vinschen dot de>
- Reply-to: cygwin-patches at cygwin dot com
On Wed, Dec 04, 2013 at 06:23:24PM +0100, Corinna Vinschen wrote:
>On Dec 4 12:00, Christopher Faylor wrote:
>> On Wed, Dec 04, 2013 at 01:04:08PM +0100, Corinna Vinschen wrote:
>> >On Dec 4 12:36, Corinna Vinschen wrote:
>> >> On Dec 4 10:32, Corinna Vinschen wrote:
>> >> > Hi guys,
>> >> > [...etc...]
>> >> > The problem is still present in the current sources.
>> >> > [...]
>> >
>> >Ouch, ouch, ouch! I tested the wrong DLL. Actually current CVS fixes
>> >this problem. Duh. Sorry for the confusion.
>> >
>> >One question, though. Assuming start is == size, then the current code
>> >in CVS extends the fd table by only 1. If that happens often, the
>> >current code would have to call ccalloc/memcpy/cfree a lot. Wouldn't
>> >it in fact be better to extend always by at least NOFILE_INCR, and to
>> >extend by (1 + start - size) only if start is > size + NOFILE_INCR?
>> >Something like
>> >
>> > size_t extendby = (start >= size + NOFILE_INCR) ? 1 + start - size : NOFILE_INCR;
>> >
>> >?
>> >
>> >Sorry again. Fortunately it's my WJM week...
>>
>> I don't think it is a common occurrence for start >= size. It is
>> usually done when something like bash dup2's stdin/stdout/stderr to a
>> high fd. Howeer, I'll check in something which guarantees that there is
>> always a NOFILE_INCR entries free after start.
>
>That might be helpful. Tcsh, for instance, always dup's it's std
>descriptors to the new fds 15-19. If it does so in this order, it would
>have to call extend 5 times.
dtable.h:#define NOFILE_INCR 32
It shouldn't extend in that scenario. The table starts with 32
elements.
cgf