flatpak-coredumpctl: Guard against unexpected coredumpctl output

The bare tuple unpack 'executable, = re.findall(...)' raises a cryptic
ValueError if the pattern matches zero or more than one line. Replace it
with an explicit length check and a clear error message.

Also pass count=1 to str.replace() so a /newroot prefix is only stripped
once and /app/ paths are passed through unchanged.
This commit is contained in:
razzeee
2026-06-08 10:34:38 +02:00
committed by Sebastian Wick
parent 8c418fa4b9
commit 6b6fdda2f6

View File

@@ -60,11 +60,17 @@ class CoreDumper():
sys.exit(dumpres.returncode)
executable, = re.findall(".*Executable: (.*)", dumpres.stderr)
matches = re.findall(r".*Executable: (.*)", dumpres.stderr)
if len(matches) != 1:
print(f"Could not determine executable from coredumpctl output "
f"(found {len(matches)} 'Executable:' line(s)).",
file=sys.stderr)
sys.exit(1)
executable = matches[0]
if not executable.startswith(("/newroot/", "/app/")):
print(f"Executable {executable} doesn't seem to be a flatpaked application.",
file=sys.stderr)
executable = executable.replace("/newroot", "")
executable = executable.replace("/newroot", "", 1)
flatpak_command.extend([executable, coredump.name])
flatpak_command.extend(shlex.split(self.gdb_arguments))