Changeset 150 for trunk/src


Ignore:
Timestamp:
03/01/09 21:17:46 (15 years ago)
Author:
tim
Message:

integrated talloc into most of the rest of the regfi library
fixed a length validation issue

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/reglookup-recover.c

    r149 r150  
    1515 * You should have received a copy of the GNU General Public License
    1616 * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
     17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    1818 *
    1919 * $Id$
     
    8484    quoted_name = malloc(1*sizeof(char));
    8585    if(quoted_name == NULL)
    86       bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     86      bailOut(REGLOOKUP_EXIT_OSERR,
     87              "ERROR: Could not allocate sufficient memory.\n");
    8788    quoted_name[0] = '\0';
    8889
     
    297298          virt_offset = cur_ancestor->parent_off;
    298299       
    299         path_element = (struct name_holder*)malloc(sizeof(struct name_holder));
     300        path_element = talloc(path_stack, struct name_holder);
    300301        if(path_element != NULL)
    301302          path_element->quoted_name = quote_string(cur_ancestor->keyname,
     
    305306           || !void_stack_push(path_stack, path_element))
    306307        {
    307           free(cur_ancestor->keyname);
    308           free(cur_ancestor);
    309           void_stack_free_deep(path_stack);
     308          /* XXX: Need to add a warning here */
     309          regfi_free_key(cur_ancestor);
     310          void_stack_free(path_stack);
    310311          return NULL;
    311312        }
     
    318319        ret_val_size += path_element->length + 1;
    319320
    320         regfi_key_free(cur_ancestor);
     321        regfi_free_key(cur_ancestor);
    321322      }
    322323    }
     
    328329  if(ret_val == NULL)
    329330  {
    330     void_stack_free_deep(path_stack);
     331    void_stack_free(path_stack);
    331332    return NULL;
    332333  }
     
    340341    ret_val_used += path_element->length + 1;
    341342    free(path_element->quoted_name);
    342     free(path_element);
     343    talloc_free(path_element);
    343344  }
    344345  void_stack_free(path_stack);
     
    532533  REGFI_NK_REC* key;
    533534  uint32 i, j;
     535  int error_code = 0;
    534536
    535537  for(i=0; i < range_list_size(unalloc_cells); i++)
     
    550552        {
    551553          fprintf(stderr, "ERROR: Couldn't add key to unalloc_keys.\n");
    552           return 20;
     554          error_code = 20;
     555          goto fail;
    553556        }
     557        talloc_steal(unalloc_keys, key);
    554558        j+=key->cell_size-8;
    555559      }
     
    561565    cur_elem = range_list_get(unalloc_keys, i);
    562566    if(!removeRange(unalloc_cells, cur_elem->offset, cur_elem->length))
    563       return 30;
     567    {
     568      error_code = 30;
     569      goto fail;
     570    }
    564571  }
    565572
    566573  return 0;
     574
     575 fail:
     576  regfi_free_key(key);
     577  return error_code;
    567578}
    568579
     
    611622             * so prune it.
    612623             */
    613             free(nk->values->elements);
    614             free(nk->values);
     624            talloc_free(nk->values);
    615625            nk->values = NULL;
    616626          }
     
    639649                                     vk->cell_size, vk))
    640650                  {
    641                     free(vk);
     651                    talloc_free(vk);
    642652                    return 30;
    643653                  }
     
    647657                }
    648658                else
    649                   free(vk);
     659                  talloc_free(vk);
    650660              }
    651661            }
  • trunk/src/reglookup.c

    r147 r150  
    275275void printValueList(REGFI_ITERATOR* iter, char* prefix)
    276276{
    277   const REGFI_VK_REC* value;
     277  REGFI_VK_REC* value;
    278278
    279279  value = regfi_iterator_first_value(iter);
     
    282282    if(!type_filter_enabled || (value->type == type_filter))
    283283      printValue(value, prefix);
     284    regfi_free_value(value);
    284285    value = regfi_iterator_next_value(iter);
    285286    printMsgs(iter->f);
     
    373374  const REGFI_NK_REC* root = NULL;
    374375  const REGFI_NK_REC* cur = NULL;
    375   const REGFI_NK_REC* sub = NULL;
     376  REGFI_NK_REC* sub = NULL;
    376377  char* path = NULL;
    377378  int key_type = regfi_type_str2val("KEY");
     
    418419          bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
    419420        }
    420 
     421       
    421422        sub = regfi_iterator_next_subkey(iter);
    422423      }
     
    433434      }
    434435
    435       cur = sub;
     436      cur = regfi_iterator_cur_key(iter);
     437      regfi_free_key(sub);
    436438      sub = regfi_iterator_first_subkey(iter);
    437439      print_this = true;
     
    456458int retrievePath(REGFI_ITERATOR* iter, char** path)
    457459{
    458   const REGFI_VK_REC* value;
     460  REGFI_VK_REC* value;
    459461  char* tmp_path_joined;
    460462  const char** tmp_path;
     
    511513      printValue(value, tmp_path_joined);
    512514
     515    regfi_free_value(value);
    513516    free(tmp_path);
    514517    free(tmp_path_joined);
Note: See TracChangeset for help on using the changeset viewer.