Bug 470074

Summary: Tab title is incorrect, appears to incorrectly parse /proc/$PID/stat for the name of a process
Product: [Applications] konsole Reporter: Clayton Townsend II <clayton>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: RESOLVED FIXED    
Severity: minor CC: clayton
Priority: NOR    
Version: 23.04.1   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: observed result of a incorrectly parsed executable

Description Clayton Townsend II 2023-05-21 01:45:17 UTC
Created attachment 159160 [details]
observed result of a incorrectly parsed executable

Run the following in a terminal window
1.  cp $(which sleep) brokentab\(title
2.  ./brokentab\(title 10000

OBSERVED RESULT
the tab title appears to incorrectly parse "(" and uses the rest of entire result of /proc/$PID/stat after the one in the executable name 
see attachment 1 [details]

EXPECTED RESULT
tab title should show just the executable name: brokentab(title

I expect the problem to occur here: https://invent.kde.org/utilities/konsole/-/blob/807382fabf79e2c63eb6215b64a711ffdf928cad/src/ProcessInfo.cpp#L425
Comment 1 Bug Janitor Service 2023-07-09 15:49:14 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/konsole/-/merge_requests/872
Comment 2 Kurt Hindenburg 2023-08-12 07:04:05 UTC
Git commit 48523348d9e1c1b2c559314c84372ebe41312638 by Kurt Hindenburg, on behalf of Theodore Wang.
Committed on 12/08/2023 at 09:04.
Pushed by hindenburg into branch 'master'.

Resolve parsing issues for certain process names to fix incorrect tab titles

Valid file names for executables can contain '(', ')' or ' '.
Some odd but legal executable names include "a) (b", "(a" and "b)".
The above examples will lead to incorrect tab titles due to incorrect
parsing of the tab names.

This change finds the index of the last character of the name field by
searching for the last occurence of ')'. The search encompasses a range
of 16 characters starting from the starting index of the name field.

This change relies on the field in /proc/%pid/stat containing the name
of the process to start with '(' and ends with ')'. It also relies on
the fact that the maximum length of the name of a process is 16 characters.
Lastly, it relies on the rest of the contents of /proc/%pid/stat not
containing parentheses.

M  +8    -8    src/ProcessInfo.cpp

https://invent.kde.org/utilities/konsole/-/commit/48523348d9e1c1b2c559314c84372ebe41312638