laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-e1d/+/33782 )
Change subject: Check return code of fcntl() in several plaaces ......................................................................
Check return code of fcntl() in several plaaces
Fixes: CID#307539, CID#307533 Change-Id: I46843174eb4699a59421dc3f3b900a3894c67081 --- M src/ctl.c M src/proto_clnt.c 2 files changed, 33 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/82/33782/1
diff --git a/src/ctl.c b/src/ctl.c index 54d37c5..8ed4a69 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -163,9 +163,20 @@ }
int flags = fcntl(ts->fd, F_GETFL); - fcntl(ts->fd, F_SETFL, flags | O_NONBLOCK); + if (flags < 0) + goto out_err; + + ret = fcntl(ts->fd, F_SETFL, flags | O_NONBLOCK); + if (ret < 0) + goto out_err;
return sd[1]; +out_err: + close(sd[0]); + close(sd[1]); + ts->fd = -1; + ts->mode = E1_TS_MODE_OFF; + return -1; }
diff --git a/src/proto_clnt.c b/src/proto_clnt.c index 6c59593..93853e9 100644 --- a/src/proto_clnt.c +++ b/src/proto_clnt.c @@ -189,7 +189,12 @@
/* Response */ int flags = fcntl(clnt->ctl_fd.fd, F_GETFL, 0); - fcntl(clnt->ctl_fd.fd, F_SETFL, flags & ~O_NONBLOCK); + if (flags < 0) + return -EIO; + + rc = fcntl(clnt->ctl_fd.fd, F_SETFL, flags & ~O_NONBLOCK); + if (rc < 0) + goto err;
while (1) { fd = -1; @@ -207,7 +212,11 @@ msgb_free(msgb); }
- fcntl(clnt->ctl_fd.fd, F_SETFL, flags); + rc = fcntl(clnt->ctl_fd.fd, F_SETFL, flags); + if (rc < 0) { + rc = -EIO; + goto err; + }
if (msg_hdr->type != (hdr->type | E1DP_RESP_TYPE)) { rc = -EPIPE;