patch: properly zeroing fd_set in clientloop
Pekka Savola
pekkas at netcore.fi
Fri Aug 3 02:11:44 EST 2001
Hello all,
This is a problem and patch reported to Red Hat Bugzilla by
Jonathan Kamens <jik at kamens.brookline.ma.us>. I'm just acting as a relay
:-)
jik has experienced some weird crashes relating to window size changes or
some similar activity. These are rather hard to trace.
Problem was fixed by patching clientloop, where fd_set structures appear
to be improperly zeroed (bytes vs bits).
FD_ZERO does not appear to work as fd_sets are just pointers in this case,
so alternative method is used.
Patch by jik attached (does not apply cleantly to CVS but the idea should
be apparent).
--
Pekka Savola "Tell me of difficulties surmounted,
Netcore Oy not those you stumble over and fall"
Systems. Networks. Security. -- Robert Jordan: A Crown of Swords
-------------- next part --------------
--- channels.h~ Wed Jun 13 15:18:05 2001
+++ channels.h Thu Jul 12 08:31:58 2001
@@ -168,6 +168,13 @@
void channel_free(int channel);
/*
+ * Zero out a select file-descriptor set. Analogous to the FD_ZERO
+ * macro, but works with different-sized sets.
+ */
+void
+channel_zero_set(fd_set *setp, int maxfdp);
+
+/*
* Allocate/update select bitmasks and add any bits relevant to channels in
* select bitmasks.
*/
--- channels.c~ Wed Jun 13 15:18:05 2001
+++ channels.c Thu Jul 12 08:32:53 2001
@@ -1160,6 +1160,14 @@
}
void
+channel_zero_set(fd_set *setp, int maxfdp)
+{
+ u_int sz = howmany(maxfdp+1, NFDBITS) * sizeof(fd_mask);
+
+ memset(setp, 0, sz);
+}
+
+void
channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
int rekeying)
{
@@ -1178,8 +1186,8 @@
*writesetp = xmalloc(sz);
*maxfdp = n;
}
- memset(*readsetp, 0, sz);
- memset(*writesetp, 0, sz);
+ channel_zero_set(*readsetp, *maxfdp);
+ channel_zero_set(*writesetp, *maxfdp);
if (!rekeying)
channel_handler(channel_pre, *readsetp, *writesetp);
--- clientloop.c~ Fri Apr 20 08:50:51 2001
+++ clientloop.c Thu Jul 12 08:33:33 2001
@@ -370,8 +370,8 @@
* We have to return, because the mainloop checks for the flags
* set by the signal handlers.
*/
- memset(*readsetp, 0, *maxfdp);
- memset(*writesetp, 0, *maxfdp);
+ channel_zero_set(*readsetp, *maxfdp);
+ channel_zero_set(*writesetp, *maxfdp);
if (errno == EINTR)
return;
More information about the openssh-unix-dev
mailing list