Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit b10662a

Browse files
committed
Remove possible infinite loops generating MAC/UUID
1 parent deefefc commit b10662a

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

virtinst/Guest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,12 +1449,17 @@ def _set_defaults(self, devlist_func, remove_func):
14491449

14501450
# Generate UUID
14511451
if self.uuid is None:
1452-
while 1:
1452+
found = False
1453+
for ignore in range(256):
14531454
self.uuid = _util.uuidToString(_util.randomUUID())
14541455
if _util.vm_uuid_collision(self.conn, self.uuid):
14551456
continue
1457+
found = True
14561458
break
14571459

1460+
if not found:
1461+
logging.debug("Failed to generate non-conflicting UUID")
1462+
14581463

14591464
###################################
14601465
# Guest Dictionary Helper methods #

virtinst/VirtualNetworkInterface.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,17 @@ def _generate_default_bridge(self):
108108

109109
def _generate_random_mac(self):
110110
if self.conn and not self._random_mac:
111-
while 1:
111+
found = False
112+
for ignore in range(256):
112113
self._random_mac = _util.randomMAC(self.conn.getType().lower())
113114
ret = self.is_conflict_net(self.conn, self._random_mac)
114115
if ret[1] is not None:
115116
continue
117+
found = True
116118
break
119+
120+
if not found:
121+
logging.debug("Failed to generate non-conflicting MAC")
117122
return self._random_mac
118123

119124
def get_source(self):

0 commit comments

Comments
 (0)