Skip to content

Commit

Permalink
packagekit: Fix crash on unexpected uname -r format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinpitt committed Mar 11, 2024
1 parent 8b28677 commit ed4dd21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/packagekit/kpatch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/verify/check-packagekit
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")

Expand Down

0 comments on commit ed4dd21

Please sign in to comment.