]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Relax entry_header, zero-length entries are valid.
authorHoward Chu <hyc@openldap.org>
Sat, 27 Aug 2011 21:35:31 +0000 (14:35 -0700)
committerHoward Chu <hyc@openldap.org>
Sat, 27 Aug 2011 21:47:20 +0000 (14:47 -0700)
servers/slapd/back-bdb/id2entry.c
servers/slapd/entry.c

index 7630126c58f9a3ced07ab10717750d0821e9874f..51238a151a68512db174c0a46fc82a4d9f6ee0ff 100644 (file)
@@ -131,24 +131,26 @@ int bdb_id2entry(
        rc = entry_header( &eh );
        if ( rc ) goto finish;
 
-       /* Get the size */
-       data.flags ^= DB_DBT_PARTIAL;
-       data.ulen = 0;
-       rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
-       if ( rc != DB_BUFFER_SMALL ) goto finish;
-
-       /* Allocate a block and retrieve the data */
-       off = eh.data - eh.bv.bv_val;
-       eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size;
-       eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
-       eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
-       data.data = eh.data;
-       data.ulen = data.size;
-
-       /* skip past already parsed nattr/nvals */
-       eh.data += off;
-
-       rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+       if ( eh.nvals ) {
+               /* Get the size */
+               data.flags ^= DB_DBT_PARTIAL;
+               data.ulen = 0;
+               rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+               if ( rc != DB_BUFFER_SMALL ) goto finish;
+
+               /* Allocate a block and retrieve the data */
+               off = eh.data - eh.bv.bv_val;
+               eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size;
+               eh.bv.bv_val = ch_malloc( eh.bv.bv_len );
+               eh.data = eh.bv.bv_val + eh.nvals * sizeof( struct berval );
+               data.data = eh.data;
+               data.ulen = data.size;
+
+               /* skip past already parsed nattr/nvals */
+               eh.data += off;
+
+               rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+       }
 
 finish:
        cursor->c_close( cursor );
@@ -157,11 +159,15 @@ finish:
                return rc;
        }
 
+       if ( eh.nvals ) {
 #ifdef SLAP_ZONE_ALLOC
-       rc = entry_decode(&eh, e, bdb->bi_cache.c_zctx);
+               rc = entry_decode(&eh, e, bdb->bi_cache.c_zctx);
 #else
-       rc = entry_decode(&eh, e);
+               rc = entry_decode(&eh, e);
 #endif
+       } else {
+               *e = entry_alloc();
+       }
 
        if( rc == 0 ) {
                (*e)->e_id = id;
index 230ad75cd6f4045fa30b32e0f112b06ce8ba31e3..9b768a9ce2952ff84c87a7f3656e5fe0d550579c 100644 (file)
@@ -814,18 +814,11 @@ int entry_header(EntryHeader *eh)
 {
        unsigned char *ptr = (unsigned char *)eh->bv.bv_val;
 
+       /* Some overlays can create empty entries
+        * so don't check for zeros here.
+        */
        eh->nattrs = entry_getlen(&ptr);
-       if ( !eh->nattrs ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "entry_header: attribute count was zero\n", 0, 0, 0);
-               return LDAP_OTHER;
-       }
        eh->nvals = entry_getlen(&ptr);
-       if ( !eh->nvals ) {
-               Debug( LDAP_DEBUG_ANY,
-                       "entry_header: value count was zero\n", 0, 0, 0);
-               return LDAP_OTHER;
-       }
        eh->data = (char *)ptr;
        return LDAP_SUCCESS;
 }