laforge has uploaded this change for review.

View Change

osmo_io: Guard osmo_iofd_register() with invalid file descriptor

Let's return an error if both osmo_iofd_setup() and osmo_iofd_register()
are called with an invalid file descriptor like -1. Either one of them
must have been called with a valid file descriptor.

Change-Id: Ie4561cefad82e1bf5d37dd1a4815f4bc805343e6
---
M src/core/osmo_io.c
1 file changed, 19 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/88/36188/1
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index 5a5e05c..d5fd008 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -673,6 +673,12 @@
if (fd >= 0)
iofd->fd = fd;

+ if (iofd->fd < 0) {
+ /* this might happen if both osmo_iofd_setup() and osmo_iofd_register() are called with -1 */
+ LOGPIO(iofd, LOGL_ERROR, "Cannot register io_fd using invalid fd == %d\n", iofd->fd);
+ return -EBADF;
+ }
+
if (osmo_iofd_ops.register_fd)
rc = osmo_iofd_ops.register_fd(iofd);
if (rc)

To view, visit change 36188. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ie4561cefad82e1bf5d37dd1a4815f4bc805343e6
Gerrit-Change-Number: 36188
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange