[Fedora-directory-commits] ldapserver/ldap/servers/slapd/back-ldbm ldbm_index_config.c, 1.9, 1.10

Noriko Hosoi nhosoi at fedoraproject.org
Fri Feb 13 19:40:33 UTC 2009


Author: nhosoi

Update of /cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv22592

Modified Files:
	ldbm_index_config.c 
Log Message:
Resolves: #464651
Summary: nsIndexType allows a blank value but does not properly apply default indexes
Description: the values retrieved from the index entry were not checked whether
it's empty or not.  With this fix, if it's empty, it issues an warning and 
returns LDAP_OPERATIONS_ERROR.



Index: ldbm_index_config.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/back-ldbm/ldbm_index_config.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ldbm_index_config.c	13 Nov 2008 23:08:19 -0000	1.9
+++ ldbm_index_config.c	13 Feb 2009 19:40:31 -0000	1.10
@@ -135,6 +135,7 @@
 {
     char *arglist[] = { NULL, NULL, NULL, NULL };
     int argc = 0, i;
+    int isFirst;
     Slapi_Attr *attr;
     const struct berval *attrValue;
     Slapi_Value *sval;
@@ -150,6 +151,12 @@
 
     slapi_attr_first_value(attr, &sval);
     attrValue = slapi_value_get_berval(sval);
+    if (NULL == attrValue->bv_val || 0 == strlen(attrValue->bv_val)) {
+        LDAPDebug(LDAP_DEBUG_ANY,
+                  "Warning: malformed index entry %s -- empty index name\n",
+                      slapi_entry_get_dn(e), 0, 0);
+        return LDAP_OPERATIONS_ERROR;
+    }
     arglist[argc++] = slapi_ch_strdup(attrValue->bv_val);
     if (index_name != NULL) {
         *index_name = slapi_ch_strdup(attrValue->bv_val);
@@ -157,15 +164,29 @@
 
     /* Get the list of index types from the entry. */
     if (0 == slapi_entry_attr_find(e, "nsIndexType", &attr)) {
+        tmpBuf[0] = 0;
+        isFirst = 1;
         for (i = slapi_attr_first_value(attr, &sval); i != -1;
              i = slapi_attr_next_value(attr, i, &sval)) {
             attrValue = slapi_value_get_berval(sval);
-            if (0 == i) {
-                tmpBuf[0] = 0;
-                ZCAT_SAFE(tmpBuf, "", attrValue->bv_val);
-            } else {
-                ZCAT_SAFE(tmpBuf, ",", attrValue->bv_val);
+            if (NULL != attrValue->bv_val && strlen(attrValue->bv_val) > 0) {
+                if (isFirst) {
+                    ZCAT_SAFE(tmpBuf, "", attrValue->bv_val);
+                    isFirst = 0;
+                } else {
+                    ZCAT_SAFE(tmpBuf, ",", attrValue->bv_val);
+                }
+            }
+        }
+        if (0 == tmpBuf[0]) {
+            LDAPDebug(LDAP_DEBUG_ANY,
+                     "Warning: malformed index entry %s -- empty nsIndexType\n",
+                     slapi_entry_get_dn(e), 0, 0);
+            slapi_ch_free_string(index_name);
+            for (i = 0; i < argc; i++) {
+                slapi_ch_free((void **)&arglist[i]);
             }
+            return LDAP_OPERATIONS_ERROR;
         }
         arglist[argc++] = slapi_ch_strdup(tmpBuf);
     }
@@ -173,13 +194,16 @@
     tmpBuf[0] = 0;
     /* Get the list of matching rules from the entry. */
     if (0 == slapi_entry_attr_find(e, "nsMatchingRule", &attr)) {
+        isFirst = 1;
         for (i = slapi_attr_first_value(attr, &sval); i != -1;
              i = slapi_attr_next_value(attr, i, &sval)) {
             attrValue = slapi_value_get_berval(sval);
-            if (0 == i) {
-                ZCAT_SAFE(tmpBuf, "", attrValue->bv_val);
-            } else {
-                ZCAT_SAFE(tmpBuf, ",", attrValue->bv_val);
+            if (NULL != attrValue->bv_val && strlen(attrValue->bv_val) > 0) {
+                if (isFirst) {
+                    ZCAT_SAFE(tmpBuf, "", attrValue->bv_val);
+                } else {
+                    ZCAT_SAFE(tmpBuf, ",", attrValue->bv_val);
+                }
             }
         }
     }
@@ -189,14 +213,16 @@
         i = slapi_attr_first_value(attr, &sval);
         if (-1 != i) {
             attrValue = slapi_value_get_berval(sval);
-            if (0 == tmpBuf[0]) {
-                PR_snprintf(tmpBuf, MAX_TMPBUF, "%s=%s",
-                            INDEX_ATTR_SUBSTRBEGIN,  attrValue->bv_val);
-            } else {
-                int tmpbuflen = strlen(tmpBuf);
-                char *p = tmpBuf + tmpbuflen;
-                PR_snprintf(p, MAX_TMPBUF - tmpbuflen, ",%s=%s",
-                            INDEX_ATTR_SUBSTRBEGIN,  attrValue->bv_val);
+            if (NULL != attrValue->bv_val && strlen(attrValue->bv_val) > 0) {
+                if (0 == tmpBuf[0]) {
+                    PR_snprintf(tmpBuf, MAX_TMPBUF, "%s=%s",
+                                INDEX_ATTR_SUBSTRBEGIN,  attrValue->bv_val);
+                } else {
+                    int tmpbuflen = strlen(tmpBuf);
+                    char *p = tmpBuf + tmpbuflen;
+                    PR_snprintf(p, MAX_TMPBUF - tmpbuflen, ",%s=%s",
+                                INDEX_ATTR_SUBSTRBEGIN,  attrValue->bv_val);
+                }
             }
         }
     }
@@ -206,14 +232,16 @@
         i = slapi_attr_first_value(attr, &sval);
         if (-1 != i) {
             attrValue = slapi_value_get_berval(sval);
-            if (0 == tmpBuf[0]) {
-                PR_snprintf(tmpBuf, MAX_TMPBUF, "%s=%s",
-                            INDEX_ATTR_SUBSTRMIDDLE,  attrValue->bv_val);
-            } else {
-                int tmpbuflen = strlen(tmpBuf);
-                char *p = tmpBuf + tmpbuflen;
-                PR_snprintf(p, MAX_TMPBUF - tmpbuflen, ",%s=%s",
-                            INDEX_ATTR_SUBSTRMIDDLE,  attrValue->bv_val);
+            if (NULL != attrValue->bv_val && strlen(attrValue->bv_val) > 0) {
+                if (0 == tmpBuf[0]) {
+                    PR_snprintf(tmpBuf, MAX_TMPBUF, "%s=%s",
+                                INDEX_ATTR_SUBSTRMIDDLE,  attrValue->bv_val);
+                } else {
+                    int tmpbuflen = strlen(tmpBuf);
+                    char *p = tmpBuf + tmpbuflen;
+                    PR_snprintf(p, MAX_TMPBUF - tmpbuflen, ",%s=%s",
+                                INDEX_ATTR_SUBSTRMIDDLE,  attrValue->bv_val);
+                }
             }
         }
     }
@@ -223,14 +251,16 @@
         i = slapi_attr_first_value(attr, &sval);
         if (-1 != i) {
             attrValue = slapi_value_get_berval(sval);
-            if (0 == tmpBuf[0]) {
-                PR_snprintf(tmpBuf, MAX_TMPBUF, "%s=%s",
-                            INDEX_ATTR_SUBSTREND,  attrValue->bv_val);
-            } else {
-                int tmpbuflen = strlen(tmpBuf);
-                char *p = tmpBuf + tmpbuflen;
-                PR_snprintf(p, MAX_TMPBUF - tmpbuflen, ",%s=%s",
-                            INDEX_ATTR_SUBSTREND,  attrValue->bv_val);
+            if (NULL != attrValue->bv_val && strlen(attrValue->bv_val) > 0) {
+                if (0 == tmpBuf[0]) {
+                    PR_snprintf(tmpBuf, MAX_TMPBUF, "%s=%s",
+                                INDEX_ATTR_SUBSTREND,  attrValue->bv_val);
+                } else {
+                    int tmpbuflen = strlen(tmpBuf);
+                    char *p = tmpBuf + tmpbuflen;
+                    PR_snprintf(p, MAX_TMPBUF - tmpbuflen, ",%s=%s",
+                                INDEX_ATTR_SUBSTREND,  attrValue->bv_val);
+                }
             }
         }
     }




More information about the Fedora-directory-commits mailing list