Skip to content

Commit 1985e0c

Browse files
authored
fix handling of win wmic source on error
* Update __init__.py for None result * Rename variable and added additional check Protects against any return that is too short which would lead to an IndexError
1 parent 87589e6 commit 1985e0c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

machineid/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ def id(winregistry: bool = True) -> str:
8989
if not id:
9090
id = __exec__("powershell.exe -ExecutionPolicy bypass -command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID")
9191
if not id:
92-
id = __exec__('wmic csproduct get uuid').split('\n')[2] \
93-
.strip()
92+
out = __exec__('wmic csproduct get uuid')
93+
if out is not None and out.count('\n')>1:
94+
id = out.split('\n')[2].strip()
95+
9496
elif platform.startswith('linux'):
9597
id = __read__('/var/lib/dbus/machine-id')
9698
if not id:

0 commit comments

Comments
 (0)