Skip to content

Commit bdc9196

Browse files
PR suggestion commit incorporation
Fixes for PR (not to include in release): Guard os.cpu_count() None to avoid crash. Enumerate subkeys without the 1024 cap; use QueryInfoKey. Close the registry handle (resource leak) and tighten the call. Signed-off-by: Shahm Najeeb <[email protected]>
1 parent c621162 commit bdc9196

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

CODE/config.ini

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ max_retry_time = 30
102102
###################################################
103103

104104
[VulnScan Settings]
105-
# Following extensions to be ignored by the model
106-
# In MB, max file size that the model is allowed to scan, if commented out disables the limit, you can also just say None
105+
# Max characters of text from each file to analyze. Set an integer or None to disable truncation.
107106
text_char_limit = None
108107
# Max workers to be used, either integer or use "auto" to make it decide the best value
109108
max_workers = auto
110-
# Sensitivity threshold for the model to flag something as a sensitive
109+
# Sensitivity threshold (0.0–1.0) for the model to flag content as sensitive
111110
threshold = 0.6
112111
# Paths for required files
113112
model = vulnscan/Model_SenseMacro.4n1.pth

CODE/usb_history.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,35 @@ def _save_history(self, message: str):
2525
@staticmethod
2626
def _get_last_write_time(root_key, sub_key_path):
2727
"""Return the precise last write time of a registry key, or None on failure."""
28+
handle = ctypes.wintypes.HANDLE()
2829
try:
29-
handle = ctypes.wintypes.HANDLE()
30-
if ctypes.windll.advapi32.RegOpenKeyExW(root_key, sub_key_path, 0, winreg.KEY_READ,
31-
ctypes.byref(handle)) != 0:
30+
advapi32 = ctypes.windll.advapi32
31+
if advapi32.RegOpenKeyExW(root_key, sub_key_path, 0, winreg.KEY_READ, ctypes.byref(handle)) != 0:
3232
return None
33-
3433
ft = ctypes.wintypes.FILETIME()
35-
if ctypes.windll.advapi32.RegQueryInfoKeyW(handle, None, None, None, None, None, None, None, None, None,
36-
None, ctypes.byref(ft)) != 0:
34+
if advapi32.RegQueryInfoKeyW(handle, None, None, None, None, None, None, None, None, None, None,
35+
ctypes.byref(ft)) != 0:
3736
return None
38-
3937
t = ((ft.dwHighDateTime << 32) + ft.dwLowDateTime) // 10
4038
return datetime(1601, 1, 1) + timedelta(microseconds=t)
41-
except Exception:
42-
return None
39+
finally:
40+
if handle:
41+
ctypes.windll.advapi32.RegCloseKey(handle)
4342

4443
@staticmethod
4544
def _enum_subkeys(root, path, warn_func):
4645
"""Yield all subkeys of a registry key, logging warnings on errors."""
4746
try:
4847
with winreg.OpenKey(root, path) as key:
49-
for i in range(1024): # reasonable upper bound to avoid infinite loops
48+
subkey_count, _, _ = winreg.QueryInfoKey(key)
49+
for i in range(subkey_count):
5050
try:
5151
yield winreg.EnumKey(key, i)
5252
except OSError as e:
53-
if e.winerror == 259: # no more data
53+
if getattr(e, "winerror", None) == 259: # ERROR_NO_MORE_ITEMS
5454
break
5555
warn_func(f"Error enumerating {path} index {i}: {e}")
56-
except Exception as e:
56+
except OSError as e:
5757
warn_func(f"Failed to open registry key {path}: {e}")
5858

5959
@staticmethod

CODE/vulnscan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
MAX_TEXT_LENGTH = int(MAX_TEXT_LENGTH) if MAX_TEXT_LENGTH not in (None, "None", "") else None
2323
# Threading
2424
NUM_WORKERS = config.get("VulnScan Settings", "max_workers", fallback="auto")
25-
NUM_WORKERS = min(32, os.cpu_count() * 2) if NUM_WORKERS == "auto" else int(NUM_WORKERS)
25+
NUM_WORKERS = min(32, (os.cpu_count() or 1) * 2) if NUM_WORKERS == "auto" else int(NUM_WORKERS)
2626
# Classification threshold
2727
SENSITIVE_THRESHOLD = float(
2828
config.get("VulnScan Settings", "threshold", fallback=0.6)) # Probability cutoff to consider a file sensitive

0 commit comments

Comments
 (0)