From ed4dd2153683f0acb988a5c9c5bdabb8a70dc434 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 11 Mar 2024 04:56:18 +0100 Subject: [PATCH] packagekit: Fix crash on unexpected `uname -r` format With custom kernels it can happen that `uname -r` does not contain a distribution release part (after a `-`). Then trying to `split()` it caused a TypeError oops. Fixes #20089 --- pkg/packagekit/kpatch.jsx | 3 +++ test/verify/check-packagekit | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/pkg/packagekit/kpatch.jsx b/pkg/packagekit/kpatch.jsx index 109271a88289..283e3fcfc64c 100644 --- a/pkg/packagekit/kpatch.jsx +++ b/pkg/packagekit/kpatch.jsx @@ -128,6 +128,9 @@ export class KpatchSettings extends React.Component { const uname_promise = cockpit.spawn(["uname", "-r"]) .then(data => { const fields = data.split("-"); + // if there's no release field, we don't have an official kernel + if (!fields[1]) + return; const kpp_kernel_version = fields[0].replaceAll(".", "_"); let release = fields[1].split("."); release = release.slice(0, release.length - 2); // remove el8.x86_64 diff --git a/test/verify/check-packagekit b/test/verify/check-packagekit index 0224cfaa8c24..36ae94c40787 100755 --- a/test/verify/check-packagekit +++ b/test/verify/check-packagekit @@ -982,6 +982,10 @@ ExecStart=/usr/local/bin/{packageName} b = self.browser m = self.machine + # pretend running custom kernel without distro release for kpatch detection robustness + self.write_file("/usr/local/bin/uname", """#!/bin/sh + if [ "$1" = "-r" ]; then echo 1.2; else exec /usr/bin/uname "$@"; fi""", perm="755") + self.createPackage("vapor", "1", "1", install=True) self.createPackage("vapor", "1", "2") @@ -996,6 +1000,7 @@ ExecStart=/usr/local/bin/{packageName} with b.wait_timeout(30): b.wait_visible("#available-updates") b.wait_in_text("#status", "1 update available") + b.wait_not_present("#kpatch-setup") b.click("#available-updates button#install-all")