From: Eugene Syromyatnikov Date: Wed, 30 Nov 2016 20:43:51 +0000 (+0300) Subject: Print syscall names only for defined syscalls X-Git-Tag: v4.15~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9936b91d9f77f799d1c9858743de7841bfb31ba4;p=strace Print syscall names only for defined syscalls The string literal "__NR_syscall_4294967295" is semantically incorrect as there is no such constant defined. * syscall.c (syscall_name): Return NULL if there is no syscall corresponding to the given number. * defs.h (syscall_name): Document this behaviour. * printsiginfo.c (print_si_info): Print syscall name with "__NR_" prefix only if there is a syscall corresponding to si_syscall number; print a plain syscall number otherwise. * tests/ptrace.c (main): Update expected output. --- diff --git a/defs.h b/defs.h index 3a0c0636..1e95a65b 100644 --- a/defs.h +++ b/defs.h @@ -457,6 +457,13 @@ extern void call_summary(FILE *); extern void clear_regs(void); extern void get_regs(pid_t pid); extern int get_scno(struct tcb *tcp); +/** + * Convert syscall number to syscall name. + * + * @param scno Syscall number. + * @return String literal corresponding to the syscall number in case latter + * is valid; NULL otherwise. + */ extern const char *syscall_name(long scno); extern const char *err_name(unsigned long err); diff --git a/printsiginfo.c b/printsiginfo.c index 1f4a8258..e92738ed 100644 --- a/printsiginfo.c +++ b/printsiginfo.c @@ -189,13 +189,21 @@ print_si_info(const siginfo_t *sip) } break; #ifdef HAVE_SIGINFO_T_SI_SYSCALL - case SIGSYS: + case SIGSYS: { + const char *scname = + syscall_name((unsigned) sip->si_syscall); + tprints(", si_call_addr="); printaddr((unsigned long) sip->si_call_addr); - tprintf(", si_syscall=__NR_%s, si_arch=", - syscall_name((unsigned) sip->si_syscall)); + tprints(", si_syscall="); + if (scname) + tprintf("__NR_%s", scname); + else + tprintf("%u", (unsigned) sip->si_syscall); + tprints(", si_arch="); printxval(audit_arch, sip->si_arch, "AUDIT_ARCH_???"); break; + } #endif default: if (sip->si_pid || sip->si_uid) diff --git a/syscall.c b/syscall.c index 0488234e..36f32799 100644 --- a/syscall.c +++ b/syscall.c @@ -990,14 +990,7 @@ shuffle_scno(unsigned long scno) const char * syscall_name(long scno) { - static char buf[sizeof("syscall_%lu") + sizeof(long)*3]; - - if (SCNO_IS_VALID(scno)) - return sysent[scno].sys_name; - else { - sprintf(buf, "syscall_%lu", scno); - return buf; - } + return SCNO_IS_VALID(scno) ? sysent[scno].sys_name: NULL; } const char * diff --git a/tests/ptrace.c b/tests/ptrace.c index 1dcfec3b..c046fa48 100644 --- a/tests/ptrace.c +++ b/tests/ptrace.c @@ -345,7 +345,7 @@ main(void) do_ptrace(PTRACE_SETSIGINFO, pid, bad_request, (unsigned long) sip); printf("ptrace(PTRACE_SETSIGINFO, %u, %#lx, {si_signo=SIGSYS" ", si_code=SYS_SECCOMP, si_errno=ENOENT, si_call_addr=%p" - ", si_syscall=__NR_syscall_%u, si_arch=AUDIT_ARCH_X86_64})" + ", si_syscall=%u, si_arch=AUDIT_ARCH_X86_64})" " = %s\n", (unsigned) pid, bad_request, sip->si_call_addr, sip->si_syscall, errstr);