mirror of https://gerrit.osmocom.org/libosmocore
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
This commit is contained in:
parent
25d5bf6570
commit
04e6f6e3da
|
@ -672,6 +672,11 @@ int osmo_iofd_register(struct osmo_io_fd *iofd, int fd)
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
iofd->fd = fd;
|
iofd->fd = fd;
|
||||||
|
else 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)
|
if (osmo_iofd_ops.register_fd)
|
||||||
rc = osmo_iofd_ops.register_fd(iofd);
|
rc = osmo_iofd_ops.register_fd(iofd);
|
||||||
|
|
Loading…
Reference in New Issue