summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-12-16 14:44:22 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-12-17 08:50:29 -0500
commitca4d33adf80cfbd94ca2ae7620520c128244a6d9 (patch)
tree4e6710e6db1893e1a1550218e3f8ee9bc8bf932b
parent1b36cbb287b53fca6b0070f1e2ca0e3f1f56946b (diff)
downloadsssd-ca4d33adf80cfbd94ca2ae7620520c128244a6d9.tar.gz
sssd-ca4d33adf80cfbd94ca2ae7620520c128244a6d9.tar.xz
sssd-ca4d33adf80cfbd94ca2ae7620520c128244a6d9.zip
Fix unchecked return value in set_nonblocking
Also fixes the same problem with set_close_on_exec https://fedorahosted.org/sssd/ticket/713
-rw-r--r--src/responder/common/responder_common.c63
1 files changed, 53 insertions, 10 deletions
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
index 231d82806..2a4a5d20c 100644
--- a/src/responder/common/responder_common.c
+++ b/src/responder/common/responder_common.c
@@ -45,18 +45,46 @@
#include "monitor/monitor_interfaces.h"
#include "sbus/sbus_client.h"
-static void set_nonblocking(int fd)
+static errno_t set_nonblocking(int fd)
{
- unsigned v;
+ int v;
+ int ferr;
+ errno_t error;
+
+ /* Get the current flags for this file descriptor */
v = fcntl(fd, F_GETFL, 0);
- fcntl(fd, F_SETFL, v | O_NONBLOCK);
+
+ errno = 0;
+ /* Set the non-blocking flag on this fd */
+ ferr = fcntl(fd, F_SETFL, v | O_NONBLOCK);
+ if (ferr < 0) {
+ error = errno;
+ DEBUG(0, ("Unable to set fd non-blocking: [%d][%s]\n",
+ error, strerror(error)));
+ return error;
+ }
+ return EOK;
}
-static void set_close_on_exec(int fd)
+static errno_t set_close_on_exec(int fd)
{
- unsigned v;
+ int v;
+ int ferr;
+ errno_t error;
+
+ /* Get the current flags for this file descriptor */
v = fcntl(fd, F_GETFD, 0);
- fcntl(fd, F_SETFD, v | FD_CLOEXEC);
+
+ errno = 0;
+ /* Set the close-on-exec flags on this fd */
+ ferr = fcntl(fd, F_SETFD, v | FD_CLOEXEC);
+ if (ferr < 0) {
+ error = errno;
+ DEBUG(0, ("Unable to set fd close-on-exec: [%d][%s]\n",
+ error, strerror(error)));
+ return error;
+ }
+ return EOK;
}
static int client_destructor(struct cli_ctx *ctx)
@@ -415,6 +443,7 @@ static int sss_dp_init(struct resp_ctx *rctx,
static int set_unix_socket(struct resp_ctx *rctx)
{
struct sockaddr_un addr;
+ errno_t ret;
/* for future use */
#if 0
@@ -462,8 +491,15 @@ static int set_unix_socket(struct resp_ctx *rctx)
* It must be readable and writable by anybody on the system. */
umask(0111);
- set_nonblocking(rctx->lfd);
- set_close_on_exec(rctx->lfd);
+ ret = set_nonblocking(rctx->lfd);
+ if (ret != EOK) {
+ goto failed;
+ }
+
+ ret = set_close_on_exec(rctx->lfd);
+ if (ret != EOK) {
+ goto failed;
+ }
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
@@ -500,8 +536,15 @@ static int set_unix_socket(struct resp_ctx *rctx)
umask(0177);
- set_nonblocking(rctx->priv_lfd);
- set_close_on_exec(rctx->priv_lfd);
+ ret = set_nonblocking(rctx->priv_lfd);
+ if (ret != EOK) {
+ goto failed;
+ }
+
+ ret = set_close_on_exec(rctx->priv_lfd);
+ if (ret != EOK) {
+ goto failed;
+ }
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;