Changeset 136 for trunk/lib


Ignore:
Timestamp:
01/23/09 12:29:51 (15 years ago)
Author:
tim
Message:

fixed various integer issues and memory allocation issues

polished error message functions and added initial messages in a few places

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/lru_cache.c

    r122 r136  
    236236        return false;
    237237      }
     238      else
     239        e->index = tmp_index;
    238240    }
    239241    else
  • trunk/lib/regfi.c

    r135 r136  
    3737/******************************************************************************
    3838 ******************************************************************************/
    39 void regfi_add_message(REGFI_FILE* file, const char* error)
    40 {
    41   /* XXX: This function is not particularly efficient, 
     39void regfi_add_message(REGFI_FILE* file, const char* fmt, ...)
     40{
     41  /* XXX: This function is not particularly efficient,
    4242   *      but then it is mostly used during errors.
    4343   */
    44   uint32 length;
    45   char* tmp;
     44  /* XXX: Should we add support for filtering by levels of severity? */
     45  uint32 buf_size, buf_used;
     46  char* new_msg;
     47  va_list args;
    4648
    4749  if(file->last_message == NULL)
    48     length = 0;
     50    buf_used = 0;
    4951  else
    50     length = strlen(error);
    51 
    52   tmp = realloc(file->last_message, length+strlen(file->last_message)+2);
    53   if(tmp == NULL)
    54     /* XXX: should we do something else here?  */
     52    buf_used = strlen(file->last_message);
     53
     54  buf_size = buf_used+strlen(fmt)+2+128;
     55  new_msg = realloc(file->last_message, buf_size);
     56  if(new_msg == NULL)
     57    /* XXX: should we report this? */
    5558    return;
    5659 
    57   if(length > 0)
    58     strcat(tmp, "\n");
    59   strcat(tmp, error);
     60  va_start(args, fmt);
     61  vsnprintf(new_msg+buf_used, buf_size-buf_used, fmt, args);
     62  va_end(args);
     63  strncat(new_msg, "\n", buf_size-1);
     64
     65  file->last_message = new_msg;
    6066}
    6167
     
    6369/******************************************************************************
    6470 ******************************************************************************/
    65 char* regfi_get_message(REGFI_FILE* file)
     71char* regfi_get_messages(REGFI_FILE* file)
    6672{
    6773  char* ret_val = file->last_message;
     
    310316      /* XXX: this is slow */
    311317      extra = strlen(sid_str) + strlen(type_str)
    312         + strlen(perms_str) + strlen(flags_str)+5;
     318        + strlen(perms_str) + strlen(flags_str) + 5;
    313319      tmp_val = realloc(ret_val, size+extra);
    314320
     
    316322      {
    317323        free(ret_val);
     324        ret_val = NULL;
    318325        failed = true;
    319326      }
     
    840847    return NULL;
    841848
    842   ret_val = (REGFI_VK_REC**)zalloc(sizeof(REGFI_VK_REC*) * num_values);
     849  ret_val = (REGFI_VK_REC**)zalloc(sizeof(REGFI_VK_REC*) * usable_num_values);
    843850  if(ret_val == NULL)
    844851  {
     
    13751382const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i)
    13761383{
    1377   REGFI_SK_REC* ret_val;
     1384  REGFI_SK_REC* ret_val = NULL;
    13781385  REGFI_HBIN* hbin;
    13791386  uint32 max_length, off;
     
    19821989    if(ret_val->data_in_offset)
    19831990    {
    1984       ret_val->data = regfi_parse_data(file, data_offset,
     1991      ret_val->data = regfi_parse_data(file, ret_val->data_off,
    19851992                                       raw_data_size, 4, strict);
    19861993    }
     
    20302037      return NULL;
    20312038
    2032     offset = offset - REGFI_REGF_SIZE;
    20332039    for(i = 0; i < length; i++)
    20342040      ret_val[i] = (uint8)((offset >> i*8) & 0xFF);
  • trunk/lib/smb_deps.c

    r134 r136  
    3333{
    3434  void* ret_val = NULL;
    35   if((ret_val = (void*)malloc(size)) != NULL)
     35  if((size > 0) && (ret_val = (void*)malloc(size)) != NULL)
    3636    memset(ret_val, 0, size);
     37
    3738  return ret_val;
    3839}
Note: See TracChangeset for help on using the changeset viewer.