summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-16 21:50:35 -0400
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commitbbc6a6a0caba41c00c1dfd9a01c7129efaa5fe56 (patch)
tree477456083f6758dc90bf7ef8daaf43c959392e82 /src/test
parentae22dea58699350462ac7100283bec6919a60765 (diff)
process-util: also filter non-printable characters in get_process_com()
We already do that in get_process_cmdline(), which is very similar in behaviour otherwise. Hence, let's be safe and also filter them in get_process_comm(). Let's try to retain as much information as we can though and escape rather than suppress unprintable characters. Let's not increase comm names beyond the kernel limit on such names however. Also see discussion about this here: https://marc.info/?l=linux-api&m=152649570404881&w=2
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-process-util.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 0d890fa46..78048a571 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -97,6 +97,38 @@ static void test_get_process_comm(pid_t pid) {
log_info("PID"PID_FMT" $PATH: '%s'", pid, strna(i));
}
+static void test_get_process_comm_escape_one(const char *input, const char *output) {
+ _cleanup_free_ char *n = NULL;
+
+ log_info("input: <%s> — output: <%s>", input, output);
+
+ assert_se(prctl(PR_SET_NAME, input) >= 0);
+ assert_se(get_process_comm(0, &n) >= 0);
+
+ log_info("got: <%s>", n);
+
+ assert_se(streq_ptr(n, output));
+}
+
+static void test_get_process_comm_escape(void) {
+ _cleanup_free_ char *saved = NULL;
+
+ assert_se(get_process_comm(0, &saved) >= 0);
+
+ test_get_process_comm_escape_one("", "");
+ test_get_process_comm_escape_one("foo", "foo");
+ test_get_process_comm_escape_one("012345678901234", "012345678901234");
+ test_get_process_comm_escape_one("0123456789012345", "012345678901234");
+ test_get_process_comm_escape_one("äöüß", "\\303\\244\\303…");
+ test_get_process_comm_escape_one("xäöüß", "x\\303\\244…");
+ test_get_process_comm_escape_one("xxäöüß", "xx\\303\\244…");
+ test_get_process_comm_escape_one("xxxäöüß", "xxx\\303\\244…");
+ test_get_process_comm_escape_one("xxxxäöüß", "xxxx\\303\\244…");
+ test_get_process_comm_escape_one("xxxxxäöüß", "xxxxx\\303…");
+
+ assert_se(prctl(PR_SET_NAME, saved) >= 0);
+}
+
static void test_pid_is_unwaited(void) {
pid_t pid;
@@ -582,6 +614,7 @@ int main(int argc, char *argv[]) {
test_get_process_comm(getpid());
}
+ test_get_process_comm_escape();
test_pid_is_unwaited();
test_pid_is_alive();
#if 0 /// UNNEEDED by elogind