Browse Source

Ticket #47571 - targetattr ACIs ignore subtype

Description: commit 85a78741dfeb636a1cf7cced1576278e65f5bb58
introduced 2 coverity issues:
12423: Explicit null dereferenced
do_search (slapd/search.c)
If attribute list contains multiple "*"s and "aci"s in ldapsearch,
the previous code attempted to add "aci" once for "*" and replacing
"aci" with normalized aci (if any) once and eliminating the duplicated
"aci"s. The code contained a null dereferenced bug. Even if duplicated
attributes are included in the attribute list, they are removed later
in send_specific_attrs. Thus, this patch simplifies the logic to avoid
the null dereference.

12422: Logically dead code
comp_cmp (slapd/attr.c)
Eliminated the dead code (case s1 == NULL AND s2 == NULL).

https://fedorahosted.org/389/ticket/47571

Reviewed by [email protected] (Thank you, Rich!!)
Noriko Hosoi 12 years ago
parent
commit
36c48b8395
2 changed files with 5 additions and 16 deletions
  1. 0 1
      ldap/servers/slapd/attr.c
  2. 5 15
      ldap/servers/slapd/search.c

+ 0 - 1
ldap/servers/slapd/attr.c

@@ -111,7 +111,6 @@ comp_cmp( const char *s1p, const char *s2p )
 		if (s1) {
 			return 1;
 		}
-		return 0;
 	} 
 	while ( *s1 && (*s1 != ';') &&
 	        *s2 && (*s2 != ';') &&

+ 5 - 15
ldap/servers/slapd/search.c

@@ -248,11 +248,10 @@ do_search( Slapi_PBlock *pb )
 	if ( attrs != NULL ) {
 		char *normaci = slapi_attr_syntax_normalize("aci");
 		int replace_aci = 0;
-		if (0 == strcasecmp(normaci, "aci")) {
-			/* normaci is identical to "aci" */
-			slapi_ch_free_string(&normaci);
+		if (!normaci) {
 			normaci = slapi_ch_strdup("aci");
-		} else {
+		} else if (strcasecmp(normaci, "aci")) {
+			/* normaci is not "aci" */
 			replace_aci = 1;
 		}
 		/* 
@@ -284,20 +283,11 @@ do_search( Slapi_PBlock *pb )
 				*p = '\0';
 			} else if (strcmp(attrs[i], LDAP_ALL_USER_ATTRS /* '*' */) == 0) {
 				if (!charray_inlist(attrs, normaci)) {
-					charray_add(&attrs, normaci); /* consumed */
-					normaci = NULL;
+					charray_add(&attrs, slapi_ch_strdup(normaci));
 				}
 			} else if (replace_aci && (strcasecmp(attrs[i], "aci") == 0)) {
 				slapi_ch_free_string(&attrs[i]);
-				if (charray_inlist(attrs, normaci)) { /* attrlist: "*" "aci" */
-					int j = i;
-					for (; attrs[j]; j++) { /* Shift the rest by 1 */
-						attrs[j] = attrs[j+1];
-					}
-				} else { /* attrlist: "aci" "*" */
-					attrs[i] = normaci; /* consumed */
-					normaci = NULL;
-				}
+				attrs[i] = slapi_ch_strdup(normaci);
 			}
 		}
 		slapi_ch_free_string(&normaci);