Browse Source

Bug 610119 - fix coverify Defect Type: Null pointer dereferences issues 12167 - 12199

https://bugzilla.redhat.com/show_bug.cgi?id=610119
Resolves: bug 610119
Bug description: Fix coverify Defect Type: Null pointer dereferences issues 12167 - 12199
Fix description: Catch possible NULL pointer in readAttrValue().
Endi S. Dewata 15 years ago
parent
commit
387ace29a5
1 changed files with 9 additions and 1 deletions
  1. 9 1
      ldap/servers/slapd/tools/ldclt/scalab01.c

+ 9 - 1
ldap/servers/slapd/tools/ldclt/scalab01.c

@@ -703,11 +703,19 @@ readAttrValue (
    */
   attrs[0] = attname;
   attrs[1] = NULL;
+
   filter = (char *)malloc((4+strlen(attname))*sizeof(char));
+  if (NULL == filter)
+  {
+    printf ("ldclt[%d]: %s: Out of memory\n", mctx.pid, ident);
+    fflush (stdout);
+    return (-1);
+  }
+
   sprintf(filter, "(%s=*)", attname);
   ret = ldap_search_ext_s (ldapCtx, dn, LDAP_SCOPE_BASE,
 			   filter, attrs, 0, NULL, NULL, NULL, -1, &res);
-  if (filter != NULL) free(filter);
+  free(filter);
   if (ret != LDAP_SUCCESS)
   {
     printf ("ldclt[%d]: %s: Cannot ldap_search (%s in %s), error=%d (%s)\n",