From 2ae13b1b501e945274fa27f2b61a77f4e2be4697 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Thu, 27 Sep 2018 00:42:27 +0200 Subject: [PATCH] syslog: do not print bufp and len for commands that ignore them * syslog.c (SYS_FUNC(syslog)): Defer printing of comma after the first argument to the specific command handlers, return RVAL_DECODED without additional printing for SYSLOG_ACTION_CLOSE, SYSLOG_ACTION_OPEN, SYSLOG_ACTION_CLEAR, SYSLOG_ACTION_CONSOLE_OFF, SYSLOG_ACTION_CONSOLE_ON, SYSLOG_ACTION_SIZE_UNREAD, SYSLOG_ACTION_SIZE_BUFFER. * tests/syslog.c: Add checks. --- syslog.c | 18 ++++++++++++++++-- tests/gen_tests.in | 2 +- tests/syslog.c | 28 ++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/syslog.c b/syslog.c index 626663ee..92d68f2a 100644 --- a/syslog.c +++ b/syslog.c @@ -18,22 +18,36 @@ SYS_FUNC(syslog) /* type */ printxval_ex(syslog_action_type, type, "SYSLOG_ACTION_???", XLAT_STYLE_VERBOSE | XLAT_STYLE_FMT_D); - tprints(", "); } switch (type) { + /* Those commands have bufp and len ignored */ + case SYSLOG_ACTION_CLOSE: + case SYSLOG_ACTION_OPEN: + case SYSLOG_ACTION_CLEAR: + case SYSLOG_ACTION_CONSOLE_OFF: + case SYSLOG_ACTION_CONSOLE_ON: + case SYSLOG_ACTION_SIZE_UNREAD: + case SYSLOG_ACTION_SIZE_BUFFER: + return RVAL_DECODED; + case SYSLOG_ACTION_READ: case SYSLOG_ACTION_READ_ALL: case SYSLOG_ACTION_READ_CLEAR: - if (entering(tcp)) + if (entering(tcp)) { + tprints(", "); return 0; + } break; default: + tprints(", "); printaddr(tcp->u_arg[1]); tprintf(", %" PRI_klu, tcp->u_arg[2]); return RVAL_DECODED; } + /* syscall exit handler for SYSLOG_ACTION_READ* */ + /* bufp */ if (syserror(tcp)) printaddr(tcp->u_arg[1]); diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 4fdf4722..8ad044a8 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -500,7 +500,7 @@ sync -a7 sync_file_range sync_file_range2 sysinfo -a14 -syslog -a36 +syslog -a35 tee time -a10 timer_create diff --git a/tests/syslog.c b/tests/syslog.c index 028514b3..151880d1 100644 --- a/tests/syslog.c +++ b/tests/syslog.c @@ -19,16 +19,32 @@ int main(void) { + static const struct cmd_str { + unsigned int cmd; + const char *str; + } no_args[] = { + { 0, "0 /* SYSLOG_ACTION_CLOSE */" }, + { 1, "1 /* SYSLOG_ACTION_OPEN */" }, + { 5, "5 /* SYSLOG_ACTION_CLEAR */" }, + { 6, "6 /* SYSLOG_ACTION_CONSOLE_OFF */" }, + { 7, "7 /* SYSLOG_ACTION_CONSOLE_ON */" }, + { 9, "9 /* SYSLOG_ACTION_SIZE_UNREAD */" }, + { 10, "10 /* SYSLOG_ACTION_SIZE_BUFFER */" }, + }; + static const kernel_ulong_t high = + (kernel_ulong_t) 0xbadc0ded00000000ULL; const long addr = (long) 0xfacefeeddeadbeefULL; - - int rc = syscall(__NR_syslog, SYSLOG_ACTION_READ, addr, -1); + int rc; + for (size_t i = 0; i < ARRAY_SIZE(no_args); i++) { + rc = syscall(__NR_syslog, high | no_args[i].cmd, addr, -1); + printf("syslog(%s) = %s\n", + no_args[i].str, sprintrc(rc)); + } + + rc = syscall(__NR_syslog, SYSLOG_ACTION_READ, addr, -1); printf("syslog(2 /* SYSLOG_ACTION_READ */, %#lx, -1) = %s\n", addr, sprintrc(rc)); - rc = syscall(__NR_syslog, SYSLOG_ACTION_SIZE_BUFFER, NULL, 10); - printf("syslog(10 /* SYSLOG_ACTION_SIZE_BUFFER */, NULL, 10) = %s\n", - sprintrc(rc)); - puts("+++ exited with 0 +++"); return 0; } -- 2.40.0