[Accel-ppp-users] [PATCH 1/3] L2TP: Fix socket() error handling in l2tp_connect()
Status: Beta
Brought to you by:
xebd
From: Guillaume N. <g....@al...> - 2012-07-12 13:22:27
|
Check if the tunnel file descriptor has been successfully created. Explicitely check for negative values to detect socket() errors. Signed-off-by: Guillaume Nault <g....@al...> --- accel-pppd/ctrl/l2tp/l2tp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index d8a98f8..5bba25e 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -384,7 +384,7 @@ static int l2tp_connect(struct l2tp_conn_t *conn) pppox_addr.pppol2tp.d_tunnel = conn->peer_tid; conn->tunnel_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); - if (!conn->ppp.fd) { + if (conn->tunnel_fd < 0) { log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno)); return -1; } @@ -392,13 +392,13 @@ static int l2tp_connect(struct l2tp_conn_t *conn) fcntl(conn->tunnel_fd, F_SETFD, fcntl(conn->tunnel_fd, F_GETFD) | FD_CLOEXEC); conn->ppp.fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); - if (!conn->ppp.fd) { + if (conn->ppp.fd < 0) { close(conn->tunnel_fd); conn->tunnel_fd = -1; log_ppp_error("l2tp: socket(AF_PPPOX): %s\n", strerror(errno)); return -1; } - + fcntl(conn->ppp.fd, F_SETFD, fcntl(conn->ppp.fd, F_GETFD) | FD_CLOEXEC); if (connect(conn->tunnel_fd, (struct sockaddr *)&pppox_addr, sizeof(pppox_addr)) < 0) { -- 1.7.10.4 |