Explorar o código

Bug 613056 - fix coverify Defect Type: Null pointer dereferences issues 11892 - 11939

https://bugzilla.redhat.com/show_bug.cgi?id=613056
Resolves: bug 613056
Bug description: Fix coverify Defect Type: Null pointer dereferences issues 11892 - 11939
description: Catch possible NULL pointer in slapi_entry_syntax_check() and slapi_mods_syntax_check().
Endi S. Dewata %!s(int64=15) %!d(string=hai) anos
pai
achega
c27be88f0f
Modificáronse 1 ficheiros con 17 adicións e 19 borrados
  1. 17 19
      ldap/servers/slapd/plugin_syntax.c

+ 17 - 19
ldap/servers/slapd/plugin_syntax.c

@@ -368,10 +368,14 @@ slapi_entry_syntax_check(
 	char *errp = &errtext[0];
 	char *errp = &errtext[0];
 	size_t err_remaining = sizeof(errtext);
 	size_t err_remaining = sizeof(errtext);
 
 
-	if (pb != NULL) {
-		slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
+	if (!pb) {
+		LDAPDebug( LDAP_DEBUG_ANY, "slapi_entry_syntax_check: NULL PBlock\n", 0, 0, 0 );
+		ret = 1;
+		goto exit;
 	}
 	}
 
 
+	slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
+
 	/* If syntax checking and logging are off, or if this is a
 	/* If syntax checking and logging are off, or if this is a
          * replicated operation, just return that the syntax is OK. */
          * replicated operation, just return that the syntax is OK. */
 	if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
 	if (((syntaxcheck == 0) && (syntaxlogging == 0) && (override == 0)) ||
@@ -404,12 +408,10 @@ slapi_entry_syntax_check(
 						}
 						}
 
 
 						if (syntaxcheck || override) {
 						if (syntaxcheck || override) {
-							if (pb) {
-								/* Append new text to any existing text. */
-								errp += PR_snprintf( errp, err_remaining,
-								    "%s: value #%d invalid per syntax\n", a->a_type, hint );
-								err_remaining -= errp - &errtext[0];
-							}
+							/* Append new text to any existing text. */
+							errp += PR_snprintf( errp, err_remaining,
+							    "%s: value #%d invalid per syntax\n", a->a_type, hint );
+							err_remaining -= errp - &errtext[0];
 							ret = 1;
 							ret = 1;
 						}
 						}
 					}
 					}
@@ -456,15 +458,13 @@ slapi_mods_syntax_check(
 	char *dn = NULL;
 	char *dn = NULL;
 	LDAPMod *mod = NULL;
 	LDAPMod *mod = NULL;
 
 
-	if (mods == NULL) {
+	if (pb == NULL || mods == NULL) {
 		ret = 1;
 		ret = 1;
 		goto exit;
 		goto exit;
 	}
 	}
 
 
-	if (pb != NULL) {
-		slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
-		slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
-	}
+	slapi_pblock_get(pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation);
+	slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn);
 
 
 	/* If syntax checking and logging are  off, or if this is a
 	/* If syntax checking and logging are  off, or if this is a
 	 * replicated operation, just return that the syntax is OK. */
 	 * replicated operation, just return that the syntax is OK. */
@@ -496,12 +496,10 @@ slapi_mods_syntax_check(
 						}
 						}
 
 
 						if (syntaxcheck || override) {
 						if (syntaxcheck || override) {
-							if (pb) {
-								/* Append new text to any existing text. */
-								errp += PR_snprintf( errp, err_remaining,
-								    "%s: value #%d invalid per syntax\n", mod->mod_type, j );
-								err_remaining -= errp - &errtext[0];
-							}
+							/* Append new text to any existing text. */
+							errp += PR_snprintf( errp, err_remaining,
+							    "%s: value #%d invalid per syntax\n", mod->mod_type, j );
+							err_remaining -= errp - &errtext[0];
 							ret = 1;
 							ret = 1;
 						}
 						}
 					}
 					}