Changeset 136 for trunk


Ignore:
Timestamp:
01/23/09 12:29:51 (16 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
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r135 r136  
    3636#include <stdio.h>
    3737#include <stdbool.h>
     38#include <stdarg.h>
    3839#include <string.h>
    3940#include <errno.h>
     
    7071/* XXX: Has MS defined a REG_QWORD_BE? */
    7172/* Not a real type in the registry */
    72 #define REG_KEY                        0x7FFFFFFF
     73#define REG_KEY                    0x7FFFFFFF
    7374
    7475#define REGFI_REGF_SIZE            0x1000 /* "regf" header block size */
     
    325326int                   regfi_close(REGFI_FILE* r);
    326327
    327 /* regfi_get_message: Get errors, warnings, and/or verbose information
    328  *                    relating to processing of the given registry file.
     328/* regfi_get_messages: Get errors, warnings, and/or verbose information
     329 *                     relating to processing of the given registry file.
    329330 *
    330331 * Arguments:
     
    334335 *   A newly allocated char* which must be free()d by the caller.
    335336 */
    336 char*                 regfi_get_message(REGFI_FILE* file);
     337char*                 regfi_get_messages(REGFI_FILE* file);
    337338
    338339REGFI_ITERATOR*       regfi_iterator_new(REGFI_FILE* fh);
     
    434435                                              REGFI_SUBKEY_LIST** lists,
    435436                                              bool strict);
    436 void                  regfi_add_message(REGFI_FILE* file, const char* error);
     437void                  regfi_add_message(REGFI_FILE* file, const char* fmt, ...);
    437438#endif  /* _REGFI_H */
  • 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}
  • trunk/src/common.c

    r134 r136  
    5252
    5353  unsigned int buf_len = sizeof(char)*(len+1);
    54   char* ret_val = malloc(buf_len);
     54  char* ret_val = NULL;
    5555  char* tmp_buf;
    5656
     57  if(buf_len > 0)
     58    ret_val = malloc(buf_len);
    5759  if(ret_val == NULL)
    5860    return NULL;
     
    155157{
    156158  char* ret_val;
    157   char* ascii;
     159  char* ascii = NULL;
    158160  char* tmp_err;
    159161  int ret_err;
    160162  *error_msg = NULL;
    161163
    162   ascii = malloc(length+1);
     164  if(length+1 > 0)
     165    ascii = malloc(length+1);
    163166  if(ascii == NULL)
    164167  {
     
    175178    free(ascii);
    176179    tmp_err = strerror(-ret_err);
    177     *error_msg = (char*)malloc(54+strlen(tmp_err));
     180    *error_msg = (char*)malloc(61+strlen(tmp_err));
    178181    if(*error_msg == NULL)
    179     {
    180       free(ascii);
    181       return NULL;
    182     }
     182      return NULL;
    183183
    184184    sprintf(*error_msg,
     
    305305    {
    306306      tmp_err = strerror(-ret_err);
    307       *error_msg = (char*)malloc(54+strlen(tmp_err));
     307      *error_msg = (char*)malloc(61+strlen(tmp_err));
    308308      if(*error_msg == NULL)
     309      {
     310        free(ascii_tmp);
    309311        return NULL;
     312      }
     313
    310314      sprintf(*error_msg, "MULTI_SZ unicode conversion"
    311315              " failed with '%s'. Quoting as binary.", tmp_err);
  • trunk/src/reglookup-recover.c

    r135 r136  
    9999  if(print_parsedraw)
    100100    free(quoted_raw);
     101  free(quoted_name);
    101102}
    102103
     
    829830      tmp_path = (char*)malloc(strlen(parent_paths[i])+strlen(tmp_name)+2);
    830831      if(tmp_path == NULL)
     832      {
     833        free(tmp_name);
    831834        return 10;
     835      }
     836
    832837      sprintf(tmp_path, "%s/%s", parent_paths[i], tmp_name);
    833838      for(j=0; j < tmp_key->num_values; j++)
  • trunk/src/reglookup.c

    r135 r136  
    255255      if((new_buf = realloc(buf, buf_len)) == NULL)
    256256      {
     257        free(name);
    257258        free(buf);
    258259        free(iter);
     
    372373  const REGFI_NK_REC* sub = NULL;
    373374  char* path = NULL;
     375  char* msgs = NULL;
    374376  int key_type = regfi_type_str2val("KEY");
    375377  bool print_this = true;
     
    377379  root = cur = regfi_iterator_cur_key(iter);
    378380  sub = regfi_iterator_first_subkey(iter);
    379  
     381  msgs = regfi_get_messages(iter->f);
     382  if(msgs != NULL)
     383    fprintf(stderr, "%s", msgs);
    380384  if(root == NULL)
    381385    bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n");
     
    455459  /* Strip any potential value name at end of path */
    456460  for(i=0;
    457       (path[i] != NULL) && (path[i+1] != NULL)
    458         && (i < REGFI_MAX_DEPTH+1+1);
     461      (path[i] != NULL) && (path[i+1] != NULL) && (i < REGFI_MAX_DEPTH+1);
    459462      i++)
    460     tmp_path[i] = path[i];
    461 
     463  { tmp_path[i] = path[i]; }
    462464  tmp_path[i] = NULL;
    463465
     
    471473    if(print_verbose)
    472474      fprintf(stderr, "VERBOSE: Found final path element as root key.\n");
     475    free(tmp_path);
    473476    return 2;
    474477  }
Note: See TracChangeset for help on using the changeset viewer.