mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
The output of /proc/<pid>/stat will show the process name in parentheses. The parsing code in read_stat() tries to filter out the parentheses, which will go wrong when the process name itself also contains parentheses, e.g. in an output like this: "2421 ((sd-pam)) S 2420 2420 2420 ..." In this case, the first closing parentheses will be taken as end marker, and the sscanf() on the remaining string will silently fail, leaving its values in uninitialized state and producing wrong data. Fix this by using strrchr() instead of strchr() to find the last closing parentheses. Also add return value checking for sscanf() and initialize the values to 0. Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>