laforge has submitted this change. (
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(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
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;
--
To view, visit
https://gerrit.osmocom.org/c/osmo-e1d/+/33782
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: I46843174eb4699a59421dc3f3b900a3894c67081
Gerrit-Change-Number: 33782
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: tnt <tnt(a)246tNt.com>
Gerrit-MessageType: merged