]> git.sur5r.net Git - openldap/commitdiff
ITS#2865 don't try to calloc 0 bytes, log an error and return instead.
authorHoward Chu <hyc@openldap.org>
Tue, 9 Dec 2003 20:10:44 +0000 (20:10 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 9 Dec 2003 20:10:44 +0000 (20:10 +0000)
Don't crash in slapcat when NULL entry is returned.

servers/slapd/entry.c
servers/slapd/tools/slapcat.c

index 605247489c3e2f85561b1ee7365a92a4d01b78aa..37c72c3cb2c9d05f162135228e9097ca6eec1109 100644 (file)
@@ -659,6 +659,16 @@ int entry_decode(struct berval *bv, Entry **e)
        BerVarray bptr;
 
        i = entry_getlen(&ptr);
+       if (!i) {
+#ifdef NEW_LOGGING
+               LDAP_LOG( OPERATION, INFO, 
+                       "entry_decode: entry length was zero\n", 0, 0, 0);
+#else
+               Debug( LDAP_DEBUG_ANY,
+                       "entry_decode: entry length was zero\n", 0, 0, 0);
+#endif
+               return LDAP_OTHER;
+       }
        x = ch_calloc(1, i);
        i = entry_getlen(&ptr);
        x->e_name.bv_val = (char *) ptr;
index 96e13e881f95aeddd669b68ad957a8aaa1c36a9c..c402dc40f7938d5533867cdee29acfbb86d73141 100644 (file)
@@ -66,6 +66,13 @@ main( int argc, char **argv )
                Entry* e = be->be_entry_get( be, id );
                op.o_bd = be;
 
+               if ( e == NULL ) {
+                       printf("# no data for entry id=%08lx\n\n", (long) id );
+                       rc = EXIT_FAILURE;
+                       if( continuemode ) continue;
+                       break;
+               }
+
                if( sub_ndn.bv_len && !dnIsSuffix( &e->e_nname, &sub_ndn ) ) {
                        be_entry_release_r( &op, e );
                        continue;
@@ -89,13 +96,6 @@ main( int argc, char **argv )
                        printf( "# id=%08lx\n", (long) id );
                }
 
-               if ( e == NULL ) {
-                       printf("# no data for entry id=%08lx\n\n", (long) id );
-                       rc = EXIT_FAILURE;
-                       if( continuemode ) continue;
-                       break;
-               }
-
                data = entry2str( e, &len );
                be_entry_release_r( &op, e );