In procfs_process_get_stat_nth() we skip to the end of the process name
by looking for the ')' after it.
However if the process name itself contains a ')' then find that instead
of the correct one.
By searching the ')' from the end of the file we can make sure to always
find the correct one.
Link: https://www.openwall.com/lists/oss-security/2022/12/21/6
return ul_strtou64(tok, re, 10);
/* skip rest of the process name */
- if (i == 2 && (p = strchr(key, ')')))
+ if (i == 2 && (p = strrchr(key, ')')))
key = p + 2;
}
bar'
COMM: 'foo
bar'
+3
+ UID: [redacted]
+ CMDLINE: './foo )bar'
+ COMM: 'foo )bar'
1: 4th 373752
2: 1th 1583
2: 4th 1165
+3: 1th 4102
+3: 4th 1165
test_cmd --one 1
test_cmd --one 2
+test_cmd --one 3
ts_finalize_subtest
test_cmd --stat-nth 2 1
test_cmd --stat-nth 2 4
+test_cmd --stat-nth 3 1
+test_cmd --stat-nth 3 4
+
ts_finalize_subtest
ts_finalize
--- /dev/null
+4102 (foo )bar) S 1165 4102 1165 34818 4102 4194304 80 0 0 0 0 0 0 0 20 0 1 0 61909 2543616 215 18446744073709551615 94697631760384 94697631760801 140728832669632 0 0 0 0 0 0 1 0 0 17 0 0 0 0 0 0 94697631772112 94697631772712 94697662554112 140728832670811 140728832670822 140728832670822 140728832671725 0