Changeset 126 for trunk/lib


Ignore:
Timestamp:
08/19/08 19:31:33 (16 years ago)
Author:
tim
Message:

improved validation and output of key class names, MULTI_SZ and other unicode strings, and improved warnings and other error messages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r125 r126  
    15101510
    15111511
    1512 
     1512/*******************************************************************
     1513 *******************************************************************/
    15131514REGF_NK_REC* regfi_parse_nk(REGF_FILE* file, uint32 offset,
    15141515                            uint32 max_size, bool strict)
     
    16351636  ret_val->keyname[ret_val->name_length] = '\0';
    16361637
    1637 
    1638   /***/
    1639  
    1640   if(ret_val->classname_length > 0
    1641      && ret_val->classname_off != REGF_OFFSET_NONE
    1642      && ret_val->classname_off == (ret_val->classname_off & 0xFFFFFFF8))
    1643   {
    1644     ret_val->classname = (char*)zalloc(ret_val->classname_length+1);
    1645     if(ret_val->classname != NULL)
    1646     {
    1647       if(!regfi_parse_cell(file->fd, ret_val->classname_off+REGF_BLOCKSIZE,
    1648                            (uint8*)ret_val->classname, ret_val->classname_length,
    1649                            &cell_length, &unalloc)
    1650          || (cell_length < ret_val->classname_length)
    1651          || (strict && unalloc))
     1638  if(ret_val->classname_off != REGF_OFFSET_NONE)
     1639  {
     1640    ret_val->classname
     1641      = regfi_parse_classname(file, ret_val->classname_off+REGF_BLOCKSIZE,
     1642                              &ret_val->classname_length, strict);
     1643    /*
     1644    if(strict && ret_val->classname == NULL)
     1645        return NULL;
     1646    */
     1647  }
     1648
     1649  return ret_val;
     1650}
     1651
     1652
     1653/*******************************************************************/
     1654/* XXX: Not currently validating against hbin length.              */
     1655/*******************************************************************/
     1656char* regfi_parse_classname(REGF_FILE* file, uint32 offset,
     1657                            uint16* name_length, bool strict)
     1658{
     1659  char* ret_val = NULL;
     1660  uint32 length;
     1661  uint32 cell_length;
     1662  bool unalloc = false;
     1663
     1664  if(*name_length > 0 && offset != REGF_OFFSET_NONE
     1665     && offset == (offset & 0xFFFFFFF8))
     1666  {   
     1667    if(!regfi_parse_cell(file->fd, offset, NULL, 0, &cell_length, &unalloc))
     1668        return NULL;
     1669
     1670    if(cell_length < *name_length)
     1671    {
     1672      if(strict)
     1673        return NULL;
     1674      *name_length = cell_length & 0xFFFFFFF8;
     1675    }
     1676   
     1677    ret_val = (char*)zalloc(*name_length);
     1678    if(ret_val != NULL)
     1679    {
     1680      length = *name_length;
     1681      if((regfi_read(file->fd, (uint8*)ret_val, &length) != 0)
     1682         || length != *name_length)
    16521683      {
    1653         /* Being careful not to reject the whole key here even when
    1654          * strict and things are obviously wrong, since it appears
    1655          * they're commonly obviously wrong.
    1656          */
    1657         free(ret_val->classname);
    1658         ret_val->classname = NULL;
    1659         return ret_val;
     1684        free(ret_val);
     1685        return NULL;
    16601686      }
    16611687
    1662       ret_val->classname[ret_val->classname_length] = '\0';
    16631688      /*printf("==> cell_length=%d, classname_length=%d, max_bytes_subkeyclassname=%d\n", cell_length, ret_val->classname_length, ret_val->max_bytes_subkeyclassname);*/
    16641689    }
    16651690  }
    1666   /***/
    1667 
    16681691
    16691692  return ret_val;
    16701693}
    1671 
    16721694
    16731695
Note: See TracChangeset for help on using the changeset viewer.