From 77add584fa8a69b262738f0b1a5697fbde306ae4 Mon Sep 17 00:00:00 2001 From: Thomas Symalla Date: Wed, 30 Mar 2022 10:22:27 +0200 Subject: [PATCH] Userland: Fix crash when inputting non-tty device into ps This PR aims to fix #13299 by avoiding assertion failure while trying to determine the pseudo tty when inputting any non-tty device device into ps. --- Userland/Utilities/ps.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/ps.cpp b/Userland/Utilities/ps.cpp index 7b6f934fc2a..a7bea5933d5 100644 --- a/Userland/Utilities/ps.cpp +++ b/Userland/Utilities/ps.cpp @@ -20,15 +20,18 @@ static ErrorOr determine_tty_pseudo_name() perror("fstat"); return Error::from_errno(saved_errno); } + int tty_device_major = major(tty_stat.st_rdev); int tty_device_minor = minor(tty_stat.st_rdev); + if (tty_device_major == 201) { return String::formatted("pts:{}", tty_device_minor); } + if (tty_device_major == 4) { return String::formatted("tty:{}", tty_device_minor); } - VERIFY_NOT_REACHED(); + return "n/a"; } ErrorOr serenity_main(Main::Arguments arguments)