summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2012-07-12 15:22:27 +0200
committerKozlov Dmitry <xeb@mail.ru>2012-07-13 10:24:39 +0400
commit7e81417530acd05125a485b7d586b0b322e26706 (patch)
treed78619de12391133a919be39396c1117acaf1762
parente04b9b2b35ed36ceb89d6991d2322210f6dd6abc (diff)
downloadaccel-ppp-7e81417530acd05125a485b7d586b0b322e26706.tar.gz
accel-ppp-7e81417530acd05125a485b7d586b0b322e26706.zip
L2TP: Check for fcntl() errors in l2tp_connect()
Add error detection to ensure the FD_CLOEXEC flag gets set for every new socket. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index 469492d3..fa760487 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -374,6 +374,7 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
{
struct sockaddr_pppol2tp pppox_addr;
int arg = 1;
+ int flg;
memset(&pppox_addr, 0, sizeof(pppox_addr));
pppox_addr.sa_family = AF_PPPOX;
@@ -388,8 +389,17 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno));
goto out_err;
}
-
- fcntl(conn->tunnel_fd, F_SETFD, fcntl(conn->tunnel_fd, F_GETFD) | FD_CLOEXEC);
+
+ flg = fcntl(conn->tunnel_fd, F_GETFD);
+ if (flg < 0) {
+ log_ppp_error("l2tp: fcntl(F_GETFD): %s\n", strerror(errno));
+ goto out_err;
+ }
+ flg = fcntl(conn->tunnel_fd, F_SETFD, flg | FD_CLOEXEC);
+ if (flg < 0) {
+ log_ppp_error("l2tp: fcntl(F_SETFD): %s\n", strerror(errno));
+ goto out_err;
+ }
conn->ppp.fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
if (conn->ppp.fd < 0) {
@@ -397,7 +407,16 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
goto out_err;
}
- fcntl(conn->ppp.fd, F_SETFD, fcntl(conn->ppp.fd, F_GETFD) | FD_CLOEXEC);
+ flg = fcntl(conn->ppp.fd, F_GETFD);
+ if (flg < 0) {
+ log_ppp_error("l2tp: fcntl(F_GETFD): %s\n", strerror(errno));
+ goto out_err;
+ }
+ flg = fcntl(conn->ppp.fd, F_SETFD, flg | FD_CLOEXEC);
+ if (flg < 0) {
+ log_ppp_error("l2tp: fcntl(F_SETFD): %s\n", strerror(errno));
+ goto out_err;
+ }
if (connect(conn->tunnel_fd, (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) {
log_ppp_error("l2tp: connect(tunnel): %s\n", strerror(errno));
@@ -418,7 +437,7 @@ static int l2tp_connect(struct l2tp_conn_t *conn)
}
conn->ppp.chan_name = _strdup(inet_ntoa(conn->addr.sin_addr));
-
+
triton_event_fire(EV_CTRL_STARTED, &conn->ppp);
if (establish_ppp(&conn->ppp))