Changeset 113 for trunk


Ignore:
Timestamp:
05/04/08 14:29:02 (16 years ago)
Author:
tim
Message:

fixed some VK record parsing bugs

added more strict checking on unallocated ranges

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/range_list.h

    r106 r113  
    176176bool range_list_split_element(range_list* rl, uint32_t index, uint32_t offset);
    177177
     178
     179/* range_list_has_range():
     180 *  Determines whether or not a specified range exists contiguously within the
     181 *  range_list.
     182 *
     183 * Arguments:
     184 *  rl     -- the range_list to search
     185 *  start  -- the offset at the beginning of the range
     186 *  length -- the length of the range
     187 *
     188 * Returns:
     189 *  true if the specified range exists and is complete, false otherwise.
     190 */
     191bool range_list_has_range(range_list* rl, uint32_t start, uint32_t length);
     192
    178193#endif
  • trunk/lib/range_list.c

    r111 r113  
    320320  return true;
    321321}
     322
     323
     324bool range_list_has_range(range_list* rl, uint32_t start, uint32_t length)
     325{
     326  int32_t idx1, idx2;
     327
     328  idx1 = range_list_find(rl, start);
     329  if(idx1 < 0)
     330    return false;
     331
     332  idx2 = range_list_find(rl, start+length);
     333  if(idx2 < 0)
     334    return false;
     335
     336  if(idx1 == idx2)
     337    return true;
     338
     339  while(idx1 != idx2)
     340  {
     341    if(rl->elements[idx1]->offset + rl->elements[idx1]->length
     342       != rl->elements[idx1+1]->offset)
     343      return false;
     344    idx1++;
     345  }
     346
     347  return true;
     348}
  • trunk/lib/regfi.c

    r111 r113  
    16651665  if(ret_val->flag & VK_FLAG_NAME_PRESENT)
    16661666  {
    1667     if(ret_val->name_length + REGFI_VK_MIN_LENGTH > ret_val->cell_size)
     1667    if(ret_val->name_length + REGFI_VK_MIN_LENGTH + 4 > ret_val->cell_size)
    16681668    {
    16691669      if(strict)
     
    16731673      }
    16741674      else
    1675         ret_val->name_length = ret_val->cell_size - REGFI_VK_MIN_LENGTH;
     1675        ret_val->name_length = ret_val->cell_size - REGFI_VK_MIN_LENGTH - 4;
    16761676    }
    16771677
    16781678    /* Round up to the next multiple of 8 */
    1679     length = (ret_val->name_length + REGFI_NK_MIN_LENGTH) & 0xFFFFFFF8;
    1680     if(length < ret_val->name_length + REGFI_NK_MIN_LENGTH)
    1681       length+=8;
     1679    cell_length = (ret_val->name_length + REGFI_VK_MIN_LENGTH + 4) & 0xFFFFFFF8;
     1680    if(cell_length < ret_val->name_length + REGFI_VK_MIN_LENGTH + 4)
     1681      cell_length+=8;
    16821682
    16831683    ret_val->valuename = (char*)zalloc(sizeof(char)*(ret_val->name_length+1));
     
    16871687      return NULL;
    16881688    }
    1689    
    1690     /* Don't need to seek, should be at the right offset */
     1689
    16911690    length = ret_val->name_length;
    16921691    if((regfi_read(file->fd, (uint8*)ret_val->valuename, &length) != 0)
     
    17001699  }
    17011700  else
    1702     length = REGFI_VK_MIN_LENGTH;
     1701    cell_length = REGFI_VK_MIN_LENGTH + 4;
    17031702
    17041703  if(unalloc)
    17051704  {
    17061705    /* If cell_size is still greater, truncate. */
    1707     if(length < ret_val->cell_size)
    1708       ret_val->cell_size = length;
     1706    if(cell_length < ret_val->cell_size)
     1707      ret_val->cell_size = cell_length;
    17091708  }
    17101709
     
    18161815        break;
    18171816     
    1818       if((cell_len == 0) || ((cell_len & 0xFFFFFFFC) != cell_len))
     1817      if((cell_len == 0) || ((cell_len & 0xFFFFFFF8) != cell_len))
    18191818        /* TODO: should report an error here. */
    18201819        break;
  • trunk/src/reglookup-recover.c

    r112 r113  
    418418
    419419
    420 bool removeRange(range_list* rl, uint32 rm_idx, uint32 offset, uint32 length)
    421 {
    422   const range_list_element* cur_elem = range_list_get(rl, rm_idx);
    423  
     420bool removeRange(range_list* rl, uint32 offset, uint32 length)
     421{
     422  int32 rm_idx;
     423  const range_list_element* cur_elem;
     424 
     425  rm_idx = range_list_find(rl, offset);
     426  if(rm_idx < 0)
     427    return false;
     428
     429  cur_elem = range_list_get(rl, rm_idx);
    424430  if(cur_elem == NULL)
    425431  {
     
    481487        }
    482488       
    483         if(!removeRange(unalloc_cells, i, key->offset, key->cell_size))
     489        if(!removeRange(unalloc_cells, key->offset, key->cell_size))
    484490          return 30;
    485491      }
     
    499505  const range_list_element* cur_elem;
    500506  uint32 i, j, num_keys, off, values_length, max_length;
    501   int32 idx;
    502507
    503508  num_keys=range_list_size(unalloc_keys);
     
    529534        if(nk->values != NULL)
    530535        {
    531           idx = range_list_find(unalloc_cells, off);
    532           if(idx < 0)
     536          if(!range_list_has_range(unalloc_cells, off, nk->cell_size))
    533537          { /* We've parsed a values-list which isn't in the unallocated list,
    534538             * so prune it.
     
    553557            if(values_length != (values_length & 0xFFFFFFF8))
    554558              values_length = (values_length & 0xFFFFFFF8) + 8;
    555             if(!removeRange(unalloc_cells, idx, off, values_length))
     559
     560            if(!removeRange(unalloc_cells, off, values_length))
    556561              return 20;
    557562
     
    560565              if(nk->values[j] != NULL)
    561566              {
    562                 idx = range_list_find(unalloc_cells, nk->values[j]->offset);
    563                 if(idx < 0)
     567                if(!range_list_has_range(unalloc_cells, nk->values[j]->offset,
     568                                         nk->values[j]->cell_size))
    564569                { /* We've parsed a value which isn't in the unallocated list,
    565570                   * so prune it.
     
    575580                   * and inspect data.
    576581                   */
    577                   if(!removeRange(unalloc_cells, idx, nk->values[j]->offset,
     582                  if(!removeRange(unalloc_cells, nk->values[j]->offset,
    578583                                  nk->values[j]->cell_size))
    579584                    return 21;
    580585
    581586                  /* Don't bother pruning or removing from unalloc_cells if
    582                    * there is no data, if it is stored the offset.
     587                   * there is no data, or it is stored in the offset.
    583588                   */
    584589                  if(nk->values[j]->data != NULL && !nk->values[j]->data_in_offset)
    585590                  {
    586591                    off = nk->values[j]->data_off+REGF_BLOCKSIZE;
    587                     idx = range_list_find(unalloc_cells, off);
    588                     if(idx < 0)
     592                    if(!range_list_has_range(unalloc_cells, off,
     593                                             nk->values[j]->data_size))
    589594                    { /* We've parsed a data cell which isn't in the unallocated
    590595                       * list, so prune it.
     
    595600                    else
    596601                    { /*A data record was recovered. Remove from unalloc_cells.*/
    597                       if(!removeRange(unalloc_cells, idx, off,
     602                      if(!removeRange(unalloc_cells, off,
    598603                                      nk->values[j]->data_size))
    599604                        return 22;
     
    638643        }
    639644       
    640         if(!removeRange(unalloc_cells, i, vk->offset, vk->cell_size))
     645        if(!removeRange(unalloc_cells, vk->offset, vk->cell_size))
    641646          return 30;
    642647      }
     
    672677        }
    673678       
    674         if(!removeRange(unalloc_cells, i, sk->offset, sk->cell_size))
     679        if(!removeRange(unalloc_cells, sk->offset, sk->cell_size))
    675680          return 30;
    676681      }
Note: See TracChangeset for help on using the changeset viewer.