From 63c09393b926f0d00317a1ca1dc6c7c992c40f4e Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Tue, 16 Jan 2018 18:09:00 +0100
Subject: [PATCH 96/96] nss-idmap: check timed muted return code
Check return values and make sure the mutex is released in case of
errors.
Related to https://pagure.io/SSSD/sssd/issue/2478
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
(cherry picked from commit 3e32cb2ad36a9dd2654c7f63469dc595f1bb8593)
---
src/sss_client/idmap/common_ex.c | 2 ++
src/sss_client/idmap/sss_nss_ex.c | 5 ++++-
src/sss_client/idmap/sss_nss_idmap.c | 5 ++++-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/sss_client/idmap/common_ex.c b/src/sss_client/idmap/common_ex.c
index 5efe9fabed7896ce674615472dbb256c4eae2144..e655bb864e063665cb56bcd3ff419e46c766478b 100644
--- a/src/sss_client/idmap/common_ex.c
+++ b/src/sss_client/idmap/common_ex.c
@@ -83,6 +83,7 @@ int sss_nss_timedlock(unsigned int timeout_ms, int *time_left_ms)
if (ret == 0) {
ret = clock_gettime(CLOCK_REALTIME, &endtime);
if (ret != 0) {
+ sss_nss_unlock();
return ret;
}
@@ -92,6 +93,7 @@ int sss_nss_timedlock(unsigned int timeout_ms, int *time_left_ms)
TIMESPECSUB(&endtime, &starttime, &diff);
left = timeout_ms - TIMESPEC_TO_MS(&diff);
if (left <= 0) {
+ sss_nss_unlock();
return EIO;
} else if (left > SSS_CLI_SOCKET_TIMEOUT) {
*time_left_ms = SSS_CLI_SOCKET_TIMEOUT;
diff --git a/src/sss_client/idmap/sss_nss_ex.c b/src/sss_client/idmap/sss_nss_ex.c
index 861b1e1e92db4f7e6e8d74a812dc3c9220711773..af6a95180656b598bcb94c209dfa821cb0275f02 100644
--- a/src/sss_client/idmap/sss_nss_ex.c
+++ b/src/sss_client/idmap/sss_nss_ex.c
@@ -202,7 +202,10 @@ int sss_get_ex(struct nss_input *inp, uint32_t flags, unsigned int timeout)
}
}
- sss_nss_timedlock(timeout, &time_left);
+ ret = sss_nss_timedlock(timeout, &time_left);
+ if (ret != 0) {
+ return ret;
+ }
if (!skip_mc && !skip_data) {
/* previous thread might already initialize entry in mmap cache */
diff --git a/src/sss_client/idmap/sss_nss_idmap.c b/src/sss_client/idmap/sss_nss_idmap.c
index 6e7685d2b1d80956b6a6668e9bbb146abd9e86ed..cbf8c11f2870e3574c75fe109cb19268e8a0b56d 100644
--- a/src/sss_client/idmap/sss_nss_idmap.c
+++ b/src/sss_client/idmap/sss_nss_idmap.c
@@ -257,7 +257,10 @@ static int sss_nss_getyyybyxxx(union input inp, enum sss_cli_command cmd,
if (timeout == NO_TIMEOUT) {
sss_nss_lock();
} else {
- sss_nss_timedlock(timeout, &time_left);
+ ret = sss_nss_timedlock(timeout, &time_left);
+ if (ret != 0) {
+ return ret;
+ }
}
nret = sss_nss_make_request_timeout(cmd, &rd, time_left, &repbuf, &replen,
--
2.14.3