summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2012-07-13 12:38:15 +0400
committerKozlov Dmitry <xeb@mail.ru>2012-07-13 12:38:15 +0400
commitbd15694dbb3c455b49c095e3d697bedece309cc5 (patch)
tree160c1588df116f3506793b024f9a0fafa188db1c /accel-pppd/ctrl
parent5c0f3b7e31f6b2eca56c462d5e39b98f59562b0b (diff)
parent7e81417530acd05125a485b7d586b0b322e26706 (diff)
downloadaccel-ppp-bd15694dbb3c455b49c095e3d697bedece309cc5.tar.gz
accel-ppp-bd15694dbb3c455b49c095e3d697bedece309cc5.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>
Diffstat (limited to 'accel-pppd/ctrl')
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index bbce6c16..b54e5e37 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -376,6 +376,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;
@@ -390,8 +391,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) {
@@ -399,7 +409,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));