This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

off-by-one problem in dtable.cc?


The following code in dtable::dup2() determines whether the fd table
should be expanded, and how much

  if ((size_t) newfd >= size)
   {
     int inc_size = NOFILE_INCR * ((newfd + NOFILE_INCR - 1) / NOFILE_INCR) -
                    size;
     extend (inc_size);
   }

Consider:

NOFILE_INCR is #defined to be 32.  If size is 32, and newfd is 32, then
inc_size will be: 32 * ((32 + 32 - 1) / 32) - 32 == 0, so the fdtable
will not be expanded, and interesting things will undoubtedly ensue!

I think it should be:

  if ((size_t) newfd >= size)
   {
     int inc_size = NOFILE_INCR * (newfd / NOFILE_INCR + 1) - size;
     extend (inc_size);
   }

Joe Buehler




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]