Changeset 147 for trunk/lib/regfi.c


Ignore:
Timestamp:
02/22/09 14:31:52 (15 years ago)
Author:
tim
Message:

added talloc library

incorporated talloc into winsec and lru_cache modules

introduced talloc into SK caching system

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r146 r147  
    2424 */
    2525
    26 #include "../include/regfi.h"
     26#include "regfi.h"
    2727
    2828
     
    762762
    763763
    764 /*******************************************************************
    765  *******************************************************************/
    766 REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, uint32 max_size, bool strict)
     764/******************************************************************************
     765 *
     766 ******************************************************************************/
     767REGFI_SK_REC* regfi_parse_sk(REGFI_FILE* file, uint32 offset, uint32 max_size,
     768                             bool strict)
    767769{
    768770  REGFI_SK_REC* ret_val;
    769   uint8* sec_desc_buf;
     771  uint8* sec_desc_buf = NULL;
    770772  uint32 cell_length, length;
    771   /*prs_struct ps;*/
    772773  uint8 sk_header[REGFI_SK_MIN_LENGTH];
    773774  bool unalloc = false;
     
    788789  }
    789790
    790   ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC));
     791  /*  ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC));*/
     792  ret_val = talloc(NULL, REGFI_SK_REC);
    791793  if(ret_val == NULL)
    792794    return NULL;
     
    805807    regfi_add_message(file, REGFI_MSG_WARN, "Invalid cell size found while"
    806808                      " parsing SK record at offset 0x%.8X.", offset);
    807     free(ret_val);
    808     return NULL;
     809    goto fail;
    809810  }
    810811
     
    824825                      " are not a multiple of 8 while parsing SK record at"
    825826                      " offset 0x%.8X.", offset);
    826     free(ret_val);
    827     return NULL;
     827    goto fail;
    828828  }
    829829
     
    833833                      " cell while parsing SK record at offset 0x%.8X.",
    834834                      offset);
    835     free(ret_val);
    836     return NULL;
    837   }
    838 
    839   sec_desc_buf = (uint8*)zalloc(ret_val->desc_size);
    840   if(ret_val == NULL)
    841   {
    842     free(ret_val);
    843     return NULL;
    844   }
     835    goto fail;
     836  }
     837
     838  sec_desc_buf = (uint8*)malloc(ret_val->desc_size);
     839  if(sec_desc_buf == NULL)
     840    goto fail;
    845841
    846842  length = ret_val->desc_size;
     
    851847                      " descriptor while parsing SK record at offset 0x%.8X.",
    852848                      offset);
    853     free(ret_val);
    854     return NULL;
    855   }
    856 
    857   if(!(ret_val->sec_desc = winsec_parse_desc(sec_desc_buf, ret_val->desc_size)))
     849    goto fail;
     850  }
     851
     852  if(!(ret_val->sec_desc = winsec_parse_desc(ret_val, sec_desc_buf,
     853                                                  ret_val->desc_size)))
    858854  {
    859855    regfi_add_message(file, REGFI_MSG_ERROR, "Failed to parse security"
    860856                      " descriptor while parsing SK record at offset 0x%.8X.",
    861857                      offset);
     858    goto fail;
     859  }
     860
     861  free(sec_desc_buf);
     862  return ret_val;
     863
     864 fail:
     865  if(sec_desc_buf != NULL)
    862866    free(sec_desc_buf);
    863     free(ret_val);
    864     return NULL;
    865   }
    866   free(sec_desc_buf);
    867 
    868 
    869   return ret_val;
     867  talloc_free(ret_val);
     868  return NULL;
    870869}
    871870
     
    11471146  const REGFI_HBIN* hbin;
    11481147  uint32 max_length;
    1149 
     1148  void* failure_ptr = NULL;
     1149 
    11501150  /* First look if we have already parsed it */
    11511151  ret_val = (REGFI_SK_REC*)lru_cache_find(file->sk_cache, &offset, 4);
     
    11651165    if(ret_val == NULL)
    11661166    { /* Cache the parse failure and bail out. */
    1167       lru_cache_update(file->sk_cache, &offset, 4, (void*)REGFI_OFFSET_NONE);
     1167      failure_ptr = talloc(NULL, uint32_t);
     1168      if(failure_ptr == NULL)
     1169        return NULL;
     1170      *(uint32_t*)failure_ptr = REGFI_OFFSET_NONE;
     1171      lru_cache_update(file->sk_cache, &offset, 4, failure_ptr);
    11681172      return NULL;
    11691173    }
     
    12871291
    12881292  /* Cache an unlimited number of SK records.  Typically there are very few. */
    1289   rb->sk_cache = lru_cache_create(0, cache_secret, true);
     1293  rb->sk_cache = lru_cache_create_ctx(NULL, 0, cache_secret, true);
    12901294
    12911295  /* Default message mask */
     
    13141318  range_list_free(file->hbins);
    13151319
     1320 
    13161321  if(file->sk_cache != NULL)
    13171322    lru_cache_destroy(file->sk_cache);
Note: See TracChangeset for help on using the changeset viewer.