Return values weren't checked in several cases which could
have lead to unhandled errors.

https://fedorahosted.org/freeipa/ticket/722

>From d7e0a194f4d57153feaf6fa239fe2e675e39f30d Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Fri, 14 Jan 2011 10:24:04 +0100
Subject: [PATCH] Unchecked return values in SLAPI plugins

Return values weren't checked in several cases which could
have lead to unhandled errors.

https://fedorahosted.org/freeipa/ticket/722
---
 daemons/ipa-kpasswd/ipa_kpasswd.c                  |    6 +++++-
 daemons/ipa-slapi-plugins/ipa-modrdn/ipa_modrdn.c  |    4 ++--
 daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c      |   14 +++++++++++---
 .../ipa-winsync/ipa-winsync-config.c               |    4 ++--
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/daemons/ipa-kpasswd/ipa_kpasswd.c b/daemons/ipa-kpasswd/ipa_kpasswd.c
index a506cec1d0c89a749fc14a91bfb6936e3533694a..dd2b4b8578aed5b156fa4d6b87fb3b7ceab8b27d 100644
--- a/daemons/ipa-kpasswd/ipa_kpasswd.c
+++ b/daemons/ipa-kpasswd/ipa_kpasswd.c
@@ -491,9 +491,13 @@ int ldap_pwd_change(char *client_name, char *realm_name, krb5_data pwd, char **e
 		goto done;
 	}
 
-	ber_printf(ctrl, "{tstO}",
+	ret = ber_printf(ctrl, "{tstO}",
 		   LDAP_TAG_EXOP_MODIFY_PASSWD_ID, userdn,
 		   LDAP_TAG_EXOP_MODIFY_PASSWD_NEW, &newpw);
+	if (ret < 0) {
+		syslog(LOG_ERR, "ber printf failed!");
+		goto done;
+	}
 
 	ret = ber_flatten(ctrl, &control);
 	if (ret < 0) {
diff --git a/daemons/ipa-slapi-plugins/ipa-modrdn/ipa_modrdn.c b/daemons/ipa-slapi-plugins/ipa-modrdn/ipa_modrdn.c
index 6049c040995840ac4e1569744b3597bacf971e3a..45a29a51079d77b107c4af46ae445551e2d9175f 100644
--- a/daemons/ipa-slapi-plugins/ipa-modrdn/ipa_modrdn.c
+++ b/daemons/ipa-slapi-plugins/ipa-modrdn/ipa_modrdn.c
@@ -748,8 +748,8 @@ static int ipamodrdn_post_op(Slapi_PBlock *pb)
                 Slapi_Value *val;
                 const char *strval;
 
-                slapi_attr_first_value(sattr, &val);
-                if (!val) {
+                ret = slapi_attr_first_value(sattr, &val);
+                if (ret == -1 || !val) {
                     LOG_FATAL("Source attr %s is empty\n", cfgentry->sattr);
                     continue;
                 }
diff --git a/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c b/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c
index 073b73cb64b56fddb3e950dde7897ea1708456b5..87d438b9754492a63ce5c298233cdd9316a3306c 100644
--- a/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c
+++ b/daemons/ipa-slapi-plugins/ipa-uuid/ipa_uuid.c
@@ -815,8 +815,16 @@ static int ipauuid_pre_op(Slapi_PBlock *pb, int modtype)
          */
         Slapi_DN *tmp_dn = slapi_sdn_new_dn_byref(dn);
         if (tmp_dn) {
-            slapi_search_internal_get_entry(tmp_dn, NULL, &e, getPluginID());
+            ret = slapi_search_internal_get_entry(tmp_dn, NULL, &e, getPluginID());
             slapi_sdn_free(&tmp_dn);
+
+            if (ret) {
+                LOG_FATAL("slapi_search_internal_get_entry failed!? Err %d\n",
+                        ret);
+                ret = LDAP_OPERATIONS_ERROR;
+                goto done;
+            }
+            
             free_entry = true;
         }
 
@@ -967,8 +975,8 @@ static int ipauuid_pre_op(Slapi_PBlock *pb, int modtype)
                         Slapi_Attr *sattr = NULL;
                         int e_numvals = 0;
 
-                        slapi_entry_attr_find(e, attr, &sattr);
-                        if (sattr) {
+                        if ((!slapi_entry_attr_find(e, attr, &sattr)) &&
+                            (NULL != sattr)) {
                             slapi_attr_get_numvalues(sattr, &e_numvals);
                             if (numvals >= e_numvals) {
                                 generate = true;
diff --git a/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync-config.c b/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync-config.c
index 1293c4c757d14d7bd50d0818e8ae5740b1c98305..a61cabb142a5e90f404fc563720bbdfa3f17ccfc 100644
--- a/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync-config.c
+++ b/daemons/ipa-slapi-plugins/ipa-winsync/ipa-winsync-config.c
@@ -702,8 +702,8 @@ internal_find_entry_get_attr_val(const Slapi_DN *basedn, int scope,
     if (entries && entries[0]) { /* found one */
         if (svs) {
             Slapi_Attr *attr = NULL;
-            slapi_entry_attr_find(entries[0], attrname, &attr);
-            if (attr) {
+            if (!slapi_entry_attr_find(entries[0], attrname, &attr) &&
+               (NULL != attr)) {
                 /* slapi_attr_get_valueset allocates svs - must be freed later */
                 slapi_attr_get_valueset(attr, svs);
             }
-- 
1.7.3.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to