Browse Source

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 fix_ownership().
Endi S. Dewata 15 years ago
parent
commit
e164ed7f97
1 changed files with 20 additions and 14 deletions
  1. 20 14
      ldap/servers/slapd/main.c

+ 20 - 14
ldap/servers/slapd/main.c

@@ -266,23 +266,29 @@ fix_ownership()
 
 	slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
 
-	if (slapdFrontendConfig->localuser != NULL) {
-		if (slapdFrontendConfig->localuserinfo == NULL) {
-			pw = getpwnam( slapdFrontendConfig->localuser );
-			if ( NULL == pw ) {
-				LDAPDebug(LDAP_DEBUG_ANY, 
-					"Unable to find user %s in system account database, "
-					"errno %d (%s)\n",
-					slapdFrontendConfig->localuser, errno, strerror(errno));
-				return; 
-			}
-			slapdFrontendConfig->localuserinfo =
-					(struct passwd *)slapi_ch_malloc(sizeof(struct passwd));
-			memcpy(slapdFrontendConfig->localuserinfo, pw, sizeof(struct passwd));
+	if (slapdFrontendConfig->localuser == NULL) {
+		LDAPDebug(LDAP_DEBUG_ANY, 
+			"Local user missing from frontend configuration\n",
+			0, 0, 0);
+		return; 
+	}
+
+	if (slapdFrontendConfig->localuserinfo == NULL) {
+		pw = getpwnam( slapdFrontendConfig->localuser );
+		if ( NULL == pw ) {
+			LDAPDebug(LDAP_DEBUG_ANY, 
+				"Unable to find user %s in system account database, "
+				"errno %d (%s)\n",
+				slapdFrontendConfig->localuser, errno, strerror(errno));
+			return; 
 		}
-		pw = slapdFrontendConfig->localuserinfo;
+		slapdFrontendConfig->localuserinfo =
+				(struct passwd *)slapi_ch_malloc(sizeof(struct passwd));
+		memcpy(slapdFrontendConfig->localuserinfo, pw, sizeof(struct passwd));
 	}
 
+	pw = slapdFrontendConfig->localuserinfo;
+
 	/* config directory needs to be owned by the local user */
 	if (slapdFrontendConfig->configdir) {
 		chown_dir_files(slapdFrontendConfig->configdir, pw, PR_FALSE);