Failure to init the mmap_cache is a soft error, so just gracefully
return a EINVAL error from public functions if the mc context is NULL
and do not segfault.

Fixes: https://fedorahosted.org/sssd/ticket/1716

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
>From 4fab067219f2002bf5e355e18a3b3cccbcd061cf Mon Sep 17 00:00:00 2001
From: Simo Sorce <[email protected]>
Date: Fri, 14 Dec 2012 08:51:09 -0500
Subject: [PATCH] Allow mmap calls to gracefully return absent ctx

This is to allow to freely call mc functions even if initialization failed.
They will now gracefully fail instead of segfaulting.
---
 src/responder/nss/nsssrv_mmap_cache.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/responder/nss/nsssrv_mmap_cache.c b/src/responder/nss/nsssrv_mmap_cache.c
index 542c837c3ce7c876603af6d90f3b790ed01ad46f..e312be19add9844edaad36e280a7daea2938bc9d 100644
--- a/src/responder/nss/nsssrv_mmap_cache.c
+++ b/src/responder/nss/nsssrv_mmap_cache.c
@@ -376,6 +376,11 @@ static errno_t sss_mmap_cache_invalidate(struct sss_mc_ctx *mcc,
 {
     struct sss_mc_rec *rec;
 
+    if (mcc == NULL) {
+        /* cache not initialized ? */
+        return EINVAL;
+    }
+
     rec = sss_mc_find_record(mcc, key);
     if (rec == NULL) {
         /* nothing to invalidate */
@@ -408,6 +413,11 @@ errno_t sss_mmap_cache_pw_store(struct sss_mc_ctx *mcc,
     size_t pos;
     int ret;
 
+    if (mcc == NULL) {
+        /* cache not initialized ? */
+        return EINVAL;
+    }
+
     ret = snprintf(uidstr, 11, "%ld", (long)uid);
     if (ret > 10) {
         return EINVAL;
@@ -472,6 +482,11 @@ errno_t sss_mmap_cache_pw_invalidate_uid(struct sss_mc_ctx *mcc, uid_t uid)
     char *uidstr;
     errno_t ret;
 
+    if (mcc == NULL) {
+        /* cache not initialized ? */
+        return EINVAL;
+    }
+
     uidstr = talloc_asprintf(NULL, "%ld", (long)uid);
     if (!uidstr) {
         return ENOMEM;
@@ -529,6 +544,11 @@ int sss_mmap_cache_gr_store(struct sss_mc_ctx *mcc,
     size_t pos;
     int ret;
 
+    if (mcc == NULL) {
+        /* cache not initialized ? */
+        return EINVAL;
+    }
+
     ret = snprintf(gidstr, 11, "%ld", (long)gid);
     if (ret > 10) {
         return EINVAL;
@@ -589,6 +609,11 @@ errno_t sss_mmap_cache_gr_invalidate_gid(struct sss_mc_ctx *mcc, gid_t gid)
     char *gidstr;
     errno_t ret;
 
+    if (mcc == NULL) {
+        /* cache not initialized ? */
+        return EINVAL;
+    }
+
     gidstr = talloc_asprintf(NULL, "%ld", (long)gid);
     if (!gidstr) {
         return ENOMEM;
-- 
1.8.0.1

_______________________________________________
sssd-devel mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to