GNOME Bugzilla – Bug 746339
GSocket kills process when fd is not a socket
Last modified: 2015-07-02 10:28:45 UTC
The gsocket.c code, particularly g_socket_details_from_fd() kills the current process if the given fd is not a valid socket. This code seems out of date with current coding practices. Nowadays it's common to receive file descriptors over environment variables from other processes like systemd. The unit files that control these file descriptors are configurable by sysadmins. It is not (necessarily) a programmer error when g_socket_details_from_fd() is called with a file descriptor that is not a socket. It can also be a system and/or configuration error. We saw this in cockpit-ws.
Created attachment 299581 [details] [review] gsocket: Don't g_error() if file-descriptor is not a socket This code was out of date with current coding practices. Nowadays it's common to receive file descriptors over environment variables from other processes like systemd. The unit files that control these file descriptors are configurable by sysadmins. It is not (necessarily) a programmer error when g_socket_details_from_fd() is called with a file descriptor that is not a socket. It can also be a system and/or configuration error.
https://github.com/cockpit-project/cockpit/issues/1931
Review of attachment 299581 [details] [review]: Seems reasonable to me, but I would also update the documentation text with something like: "Since GLib 2.46, it is no longer a fatal error to call this on a non-socket descriptor. Instead, a GError will be set with code %G_IO_ERROR_FAILED". You might also want to add a GIOError mapping ENOTSOCK -> G_IO_ERROR_NOT_SOCKET?
Comment on attachment 299581 [details] [review] gsocket: Don't g_error() if file-descriptor is not a socket agree with Colin on updating the docs, but I don't think we need a new error code
Created attachment 306593 [details] [review] gsocket: Don't g_error() if file-descriptor is not a socket This code was out of date with current coding practices. Nowadays it's common to receive file descriptors over environment variables from other processes like systemd. The unit files that control these file descriptors are configurable by sysadmins. It is not (necessarily) a programmer error when g_socket_details_from_fd() is called with a file descriptor that is not a socket. It can also be a system and/or configuration error.
Made changes suggested. Merged.