laforge has uploaded this change for review.
osmo_iofd_register: Guard against calls from wrong state
Right now the IOFD_FLAG_CLOSED flag represents a mixture of both
closed and registered state. What we want to prevent against is
repeat calls to osmo_iofd_register() of an io_fd that's already
registered.
Since osmo_iofd_register() itself will un-set the IOFD_FLAG_CLOSED, we
can use it to guard against such invalid duplicate registration
attempts.
Change-Id: I422fc5eded41831663413e7118d4e012013a9ac9
---
M src/core/osmo_io.c
1 file changed, 24 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/89/36189/1
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index d5fd008..c1d206b 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -670,6 +670,12 @@
{
int rc = 0;
+ /* guard against repeat calls to osmo_iofd_register from the wrong state. */
+ if (!IOFD_FLAG_ISSET(iofd, IOFD_FLAG_CLOSED)) {
+ LOGPIO(iofd, LOGL_ERROR, "Attempting to re-register an already registered io_fd\n");
+ return -EINVAL;
+ }
+
if (fd >= 0)
iofd->fd = fd;
To view, visit change 36189. To unsubscribe, or for help writing mail filters, visit settings.