Changeset 255


Ignore:
Timestamp:
06/13/11 15:15:08 (14 years ago)
Author:
tim
Message:

fixed error condition deadlock in regfi
prevented early garbage collection of hive file handles
fixed module imports under python3

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r253 r255  
    106106    global recurseKey_stat
    107107    global recurseValue_stat
    108     recurseKey_stat += (key.mtime.low^key.mtime.high - key.max_bytes_subkeyname) * key.flags
     108    recurseKey_stat += (key.mtime - key.max_bytes_subkeyname) * key.flags
    109109    for v in key.values:
    110110        recurseValue_stat += (v.data_off - v.data_size) / (1.0 + v.flags) + v.data_in_offset
    111         value = key.values[v.name]
    112         if v != value:
    113             print("WARNING: iterator value '%s' does not match dictionary value '%s'."
    114                   % (v.name, value.name))
     111        try:
     112            value = key.values[v.name]
     113            if v != value:
     114                print("WARNING: iterator value '%s' does not match dictionary value '%s'."
     115                      % (v.name, value.name))
     116        except Exception as e:
     117                print("WARNING: iterator value name '%s' is not retrievable via value list\n"
     118                      % (v.name,))
     119       
    115120
    116121def recurseTree(cur, operation):
     
    258263    print("  Security stat: %d" % stat)
    259264
     265
    260266tests = {
    261267    "iterTallyNames":iterTallyNames,
     
    286292    if st not in tests:
    287293        usage()
    288         sys.stderr.write("ERROR: %s not a valid test type" % st)
     294        sys.stderr.write("ERROR: %s not a valid test type\n\n" % st)
    289295        sys.exit(1)
    290296
     
    296302start_time = time.time()
    297303for hname,fh in files:
    298     hive = pyregfi.Hive(fh)
     304    #hive = pyregfi.Hive(fh)
     305    hive = pyregfi.openHive(hname)
    299306    for tname in selected_tests:
    300307        t = tests[tname]
  • trunk/lib/regfi.c

    r253 r255  
    15111511      regfi_log_add(REGFI_LOG_WARN, "Could not parse cell at offset"
    15121512                    " 0x%.8X while searching for root key.", cur_offset);
    1513       return NULL;
     1513      goto error_locked;
    15141514    }
    15151515
     
    15301530  }
    15311531
     1532  return NULL;
     1533
     1534 error_locked:
     1535  regfi_unlock(file, &file->cb_lock, "regfi_find_root_nk");
    15321536  return NULL;
    15331537}
  • trunk/python/pyregfi/__init__.py

    r253 r255  
    258258    # Memory management for most regfi structures is taken care of here
    259259    def __del__(self):
    260         regfi.regfi_free_record(self._hive.file, self._base)
     260        if self._base:
     261            regfi.regfi_free_record(self._hive.file, self._base)
    261262
    262263
     
    683684    file = None
    684685    raw_file = None
    685     _root = None
     686    _fh = None
     687    #_root = None
     688
    686689
    687690    ## The root Key of this Hive
     
    723726        # The fileno method may not exist, or it may throw an exception
    724727        # when called if the file isn't backed with a descriptor.
     728        self._fh = fh
    725729        fn = None
    726730        try:
     
    766770   
    767771    def __del__(self):
    768         regfi.regfi_free(self.file)
    769         if self.raw_file != None:
    770             self.raw_file = None
    771 
     772        if self.file:
     773            regfi.regfi_free(self.file)
    772774
    773775    def __iter__(self):
  • trunk/python/pyregfi/structures.py

    r253 r255  
    9797
    9898
    99 from winsec import *
     99from .winsec import *
    100100
    101101REGFI_VK._fields_ = [('offset', c_uint32),
  • trunk/python/pyregfi/winsec.py

    r254 r255  
    1111import ctypes.util
    1212from ctypes import *
    13 import structures
     13from .structures import regfi
    1414
    1515is_win32 = hasattr(ctypes, 'windll')
     
    7777                        ('dacl', POINTER(WINSEC_ACL)),
    7878                        ]
    79 
    80 structures.regfi.winsec_sid2str.argtypes = [POINTER(WINSEC_DOM_SID)]
    81 structures.regfi.winsec_sid2str.restype = POINTER(c_char)
     79regfi.winsec_sid2str.argtypes = [POINTER(WINSEC_DOM_SID)]
     80regfi.winsec_sid2str.restype = POINTER(c_char)
    8281
    8382
     
    128127        self.inherited_object = _guid2uuid(ace.inh_guid)
    129128
    130         c_str = structures.regfi.winsec_sid2str(ace.trustee)
     129        c_str = regfi.winsec_sid2str(ace.trustee)
    131130        self.trustee = ctypes.cast(c_str, c_char_p).value.decode('utf-8', 'replace')
    132131        libc.free(c_str)
     
    153152
    154153    def __init__(self, sec_desc):
    155         c_str = structures.regfi.winsec_sid2str(sec_desc.owner_sid)
     154        c_str = regfi.winsec_sid2str(sec_desc.owner_sid)
    156155        self.owner = ctypes.cast(c_str, c_char_p).value.decode('utf-8', 'replace')
    157156        libc.free(c_str)
    158157       
    159         c_str = structures.regfi.winsec_sid2str(sec_desc.grp_sid)
     158        c_str = regfi.winsec_sid2str(sec_desc.grp_sid)
    160159        self.group = ctypes.cast(c_str, c_char_p).value.decode('utf-8', 'replace')
    161160        libc.free(c_str)
Note: See TracChangeset for help on using the changeset viewer.