PATCH: Fix for Uninitialized memory read in giounix.c in glib
- From: Benjamin Kahn <xkahn cybersites com>
- To: gtk-devel-list redhat com
- Subject: PATCH: Fix for Uninitialized memory read in giounix.c in glib
- Date: Thu, 6 Apr 2000 13:54:52 -0400 (EDT)
I have a multi-threaded, module-loading application which uses a
lot of networking code, and is based on glib. (Okay, okay, it's a chat
server which will eventually be IETF IMPP compatible. Once the spec
settles down a little.)
A few weeks ago I noticed a bug in the application under Linux
where it would try to accept a non-existent connection. (Which would
block.) I read this in the Linux man page:
If you want accept to never block the listening socket
needs to have the non blocking flag set. Assuming that
there is always a connection waiting after select returned
true is not reliable, because the connection might be
removed by an asynchronous network error between the
select/poll returning and the accept call. The application
would hang then if the listen socket is not non blocking.
so I wetn away thinking it was a Linux problem. (That notice doesn't
appear on other OS's man pages.) Either way, I switched to non-blocking
sockets, and printed out any NULL values that came through.
I got a lot of them. On other machines too. And, about that
time, I starting trying to find problems with my program with purify.
Purify reported that revents in the GPollFD is sometimes read
uninitialized. This means that g_io_check (or whatever) is being called
before poll_func. I haven't figured out HOW this happens, but it seems to
be true.
This patch initializes revents to zero. This fixed the ghost
accepts, and makes purify shut up. Sorry about the long story. I get
chatty when I haven't had much sleep. ;^)
--- glib-1.2.7-orig/giounix.c Tue Mar 23 16:57:39 1999
+++ glib-1.2.7/giounix.c Thu Apr 6 02:13:47 2000
@@ -286,6 +286,7 @@
watch->pollfd.fd = unix_channel->fd;
watch->pollfd.events = condition;
+ watch->pollfd.revents = 0; /* This might get read before a
poll. Zero is safe. */
g_main_add_poll (&watch->pollfd, priority);
-Ben
------------------------------------ |\ _,,,--,,_ ,) ----------
Benjamin Kahn /,`.-'`' -, ;-;;'
(212) 924 - 2220 ext 201 |,4- ) )-,_ ) /\
ben@cybersites.com --------------- '---''(_/--' (_/-' ---------------
Q: Why does it crash?
A: Woah! You should have seen it last week!
-- Linux NETFILTER-HOWTO
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]