Browse Source

Bug 630096 - (cov#15447) - Check return value of idl_append_extend()

We should check the return type of idl_append_extend(), though it does
not seem possible that the return type will be anything other than 0.
The only time idl_append_extend() returns anything other than 0 is
when it is unable to allocate memory.  Since the underlying allocation
function is slapi_ch_calloc(), the server will just exit if it runs
out of memory, which means we will never return up through
idl_append_extend().  The right thing to do from a code standpoint is
to still check for the return value though.
Nathan Kinder 15 years ago
parent
commit
b2962bd5ec
1 changed files with 13 additions and 2 deletions
  1. 13 2
      ldap/servers/slapd/back-ldbm/idl_new.c

+ 13 - 2
ldap/servers/slapd/back-ldbm/idl_new.c

@@ -154,6 +154,7 @@ IDList * idl_new_fetch(
 )
 {
     int ret = 0;
+    int idl_rc = 0;
     DBC *cursor = NULL;
     IDList *idl = NULL;
     DBT key;
@@ -246,7 +247,12 @@ IDList * idl_new_fetch(
             memcpy(&id, dataret.data, sizeof(ID));
 
             /* we got another ID, add it to our IDL */
-            idl_append_extend(&idl, id);
+            idl_rc = idl_append_extend(&idl, id);
+            if (idl_rc) {
+                LDAPDebug(LDAP_DEBUG_ANY, "unable to extend id list (err=%d)\n", idl_rc, 0, 0);
+                idl_free(idl); idl = NULL;
+                goto error;
+            }
 
             count++;
         }
@@ -275,7 +281,12 @@ IDList * idl_new_fetch(
             break;
         }
         /* we got another ID, add it to our IDL */
-        idl_append_extend(&idl, id);
+        idl_rc = idl_append_extend(&idl, id);
+        if (idl_rc) {
+            LDAPDebug(LDAP_DEBUG_ANY, "unable to extend id list (err=%d)\n", idl_rc);
+            idl_free(idl); idl = NULL;
+            goto error;
+        }
 #if defined(DB_ALLIDS_ON_READ)	
 		/* enforce the allids read limit */
 		if (count > idl_new_get_allidslimit(a)) {