After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 765959 - socket: set fd field to -1 after closing socket
socket: set fd field to -1 after closing socket
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2016-05-04 07:39 UTC by Christian Hergert
Modified: 2016-05-04 13:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
socket: set fd field to -1 after closing socket (1.66 KB, patch)
2016-05-04 07:39 UTC, Christian Hergert
none Details | Review
socket: set fd field to -1 after closing socket (1.28 KB, patch)
2016-05-04 07:41 UTC, Christian Hergert
committed Details | Review

Description Christian Hergert 2016-05-04 07:39:48 UTC
We were leaving the fd to the no-longer valid fd. While accessing this after
calling close is likely a programmer error, seems prudent to defend against.

As there were no tests verifying that the fd should have been the same after
closing, I'm inclined to believe it was not done on purpose.
Comment 1 Christian Hergert 2016-05-04 07:39:54 UTC
Created attachment 327268 [details] [review]
socket: set fd field to -1 after closing socket

This ensures that g_socket_get_fd() will return -1 after the socket has
been closed.
Comment 2 Christian Hergert 2016-05-04 07:41:32 UTC
Created attachment 327269 [details] [review]
socket: set fd field to -1 after closing socket

This ensures that g_socket_get_fd() will return -1 after the socket has
been closed.
Comment 3 Matthias Clasen 2016-05-04 10:59:25 UTC
Review of attachment 327269 [details] [review]:

Seems ok to me. Did you hit this in a real-life situation somewhere ?
Comment 4 Christian Hergert 2016-05-04 11:01:32 UTC
I was spelunking through gsocket while trying to track down an inf loop in bug 764823. Just something I noticed. Seems low priority at best.
Comment 5 Dan Winship 2016-05-04 13:39:31 UTC
Comment on attachment 327269 [details] [review]
socket: set fd field to -1 after closing socket

I can't think of any good reason why you'd want to call g_socket_get_fd() after closing the socket, but I can imagine people doing it for bad reasons maybe (using the fd as a hash table key?) so I'd say only commit this to master, not the stable branch just in case.
Comment 6 Christian Hergert 2016-05-04 13:49:43 UTC
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.