r23779: Change from v2 or later to v3 or later.
[tprouty/samba.git] / source3 / registry / regfio.c
index 954f4ae7bd0b6916984c3e783a429ef1d1f07bb4..d6440f1d9b88bd98314bf7b8e7861a4ce39dd0a9 100644 (file)
@@ -5,7 +5,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -642,8 +642,12 @@ static BOOL hbin_prs_lf_records( const char *desc, REGF_HBIN *hbin, int depth, R
                return False;
 
        if ( UNMARSHALLING(&hbin->ps) ) {
-               if ( !(lf->hashes = PRS_ALLOC_MEM( &hbin->ps, REGF_HASH_REC, lf->num_keys )) )
-                       return False;
+               if (lf->num_keys) {
+                       if ( !(lf->hashes = PRS_ALLOC_MEM( &hbin->ps, REGF_HASH_REC, lf->num_keys )) )
+                               return False;
+               } else {
+                       lf->hashes = NULL;
+               }
        }
 
        for ( i=0; i<lf->num_keys; i++ ) {
@@ -1646,12 +1650,19 @@ static BOOL create_vk_record( REGF_FILE *file, REGF_VK_REC *vk, REGISTRY_VALUE *
        if ( vk->data_size > sizeof(uint32) ) {
                uint32 data_size = ( (vk->data_size+sizeof(uint32)) & 0xfffffff8 ) + 8;
 
-               vk->data = TALLOC_MEMDUP( file->mem_ctx, regval_data_p(value), vk->data_size );
+               vk->data = (uint8 *)TALLOC_MEMDUP( file->mem_ctx,
+                                                  regval_data_p(value),
+                                                  vk->data_size );
+               if (vk->data == NULL) {
+                       return False;
+               }
 
                /* go ahead and store the offset....we'll pick this hbin block back up when 
                   we stream the data */
 
-               data_hbin = find_free_space(file, data_size );
+               if ((data_hbin = find_free_space(file, data_size )) == NULL) {
+                       return False;
+               }
                vk->data_off = prs_offset( &data_hbin->ps ) + data_hbin->first_hbin_off - HBIN_HDR_SIZE;
        }
        else {
@@ -1712,7 +1723,9 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
 
        size = nk_record_data_size( nk );
        nk->rec_size = ( size - 1 ) ^ 0XFFFFFFFF;
-       nk->hbin = find_free_space( file, size );
+       if ((nk->hbin = find_free_space( file, size )) == NULL) {
+               return NULL;
+       }
        nk->hbin_off = prs_offset( &nk->hbin->ps );
 
        /* Update the hash record in the parent */
@@ -1739,14 +1752,15 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
        if ( sec_desc ) {
                uint32 sk_size = sk_record_data_size( sec_desc );
                REGF_HBIN *sk_hbin;
-               REGF_SK_REC *tmp = NULL;
 
                /* search for it in the existing list of sd's */
 
                if ( (nk->sec_desc = find_sk_record_by_sec_desc( file, sec_desc )) == NULL ) {
                        /* not found so add it to the list */
 
-                       sk_hbin = find_free_space( file, sk_size );
+                       if (!(sk_hbin = find_free_space( file, sk_size ))) {
+                               return NULL;
+                       }
 
                        if ( !(nk->sec_desc = TALLOC_ZERO_P( file->mem_ctx, REGF_SK_REC )) )
                                return NULL;
@@ -1766,7 +1780,7 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                        /* size value must be self-inclusive */
                        nk->sec_desc->size      = sec_desc_size(sec_desc) + sizeof(uint32);
 
-                       DLIST_ADD_END( file->sec_desc_list, nk->sec_desc, tmp );
+                       DLIST_ADD_END( file->sec_desc_list, nk->sec_desc, REGF_SK_REC *);
 
                        /* update the offsets for us and the previous sd in the list.
                           if this is the first record, then just set the next and prev
@@ -1803,7 +1817,9 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                uint32 namelen;
                int i;
                
-               nk->subkeys.hbin = find_free_space( file, lf_size );
+               if (!(nk->subkeys.hbin = find_free_space( file, lf_size ))) {
+                       return NULL;
+               }
                nk->subkeys.hbin_off = prs_offset( &nk->subkeys.hbin->ps );
                nk->subkeys.rec_size = (lf_size-1) ^ 0xFFFFFFFF;
                nk->subkeys_off = prs_offset( &nk->subkeys.hbin->ps ) + nk->subkeys.hbin->first_hbin_off - HBIN_HDR_SIZE;
@@ -1811,8 +1827,12 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                memcpy( nk->subkeys.header, "lf", REC_HDR_SIZE );
                
                nk->subkeys.num_keys = nk->num_subkeys;
-               if ( !(nk->subkeys.hashes = TALLOC_ZERO_ARRAY( file->mem_ctx, REGF_HASH_REC, nk->subkeys.num_keys )) )
-                       return NULL;
+               if (nk->subkeys.num_keys) {
+                       if ( !(nk->subkeys.hashes = TALLOC_ZERO_ARRAY( file->mem_ctx, REGF_HASH_REC, nk->subkeys.num_keys )) )
+                               return NULL;
+               } else {
+                       nk->subkeys.hashes = NULL;
+               }
                nk->subkey_index = 0;
 
                /* update the max_bytes_subkey{name,classname} fields */
@@ -1830,11 +1850,17 @@ static int hashrec_cmp( REGF_HASH_REC *h1, REGF_HASH_REC *h2 )
                uint32 vlist_size = ( ( nk->num_values * sizeof(uint32) ) & 0xfffffff8 ) + 8;
                int i;
                
-               vlist_hbin = find_free_space( file, vlist_size );
+               if (!(vlist_hbin = find_free_space( file, vlist_size ))) {
+                       return NULL;
+               }
                nk->values_off = prs_offset( &vlist_hbin->ps ) + vlist_hbin->first_hbin_off - HBIN_HDR_SIZE;
        
-               if ( !(nk->values = TALLOC_ARRAY( file->mem_ctx, REGF_VK_REC, nk->num_values )) )
-                       return NULL;
+               if (nk->num_values) {
+                       if ( !(nk->values = TALLOC_ARRAY( file->mem_ctx, REGF_VK_REC, nk->num_values )) )
+                               return NULL;
+               } else {
+                       nk->values = NULL;
+               }
 
                /* create the vk records */