Skip to content

Commit ae7bc47

Browse files
aborah-sudoikerexxe
authored andcommitted
fix(sbus): prevent IndexError in methods with no output args
Skip output parsing when self.output is empty, which happens for void methods like UpdateMemberList. Return None instead of attempting to access values[0].
1 parent e84826b commit ae7bc47

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

sssd_test_framework/utils/sbus.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ def __call__(self, *args) -> Any:
177177
raise RuntimeError("Execution failed: no interface.")
178178

179179
objargs = []
180-
if self.input is not None:
180+
if self.input is not None and len(self.input) > 0:
181181
for i in range(len(self.input)):
182182
obj = self.input[i].mimic()
183183
try:
184184
obj.value = args[i]
185185
except IndexError:
186186
raise RuntimeError(
187-
f"Execution failed: {len(self.input)} " f"arguments required but only {i} provided."
187+
f"Execution failed: {len(self.input)} arguments required but only {i} provided."
188188
)
189189
objargs.append(obj)
190190

@@ -193,19 +193,21 @@ def __call__(self, *args) -> Any:
193193
if res.rc != 0:
194194
raise RuntimeError(f'Execution of \'{self.child.attrib["name"]}{args}\' failed: ' + res.stderr)
195195

196-
if self.output is None:
197-
ret = None
198-
else:
199-
values = []
200-
result = DBUSResult(res.stdout)
201-
for i in range(len(self.output)):
202-
obj = self.output[i].mimic()
203-
obj.parse(result)
204-
values.append(obj.value)
205-
206-
ret = tuple(values) if len(values) > 1 else values[0]
207-
208-
return ret
196+
# Skip output processing if no output is expected
197+
if self.output is None or len(self.output) == 0:
198+
return None
199+
200+
values = []
201+
result = DBUSResult(res.stdout)
202+
for i in range(len(self.output)):
203+
obj = self.output[i].mimic()
204+
obj.parse(result)
205+
values.append(obj.value)
206+
207+
# Handle empty results safely
208+
if not values:
209+
return None
210+
return tuple(values) if len(values) > 1 else values[0]
209211

210212

211213
class DBUSObject:

0 commit comments

Comments
 (0)