]> granicus.if.org Git - strace/commitdiff
Print syscall names only for defined syscalls
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 30 Nov 2016 20:43:51 +0000 (23:43 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 1 Dec 2016 00:08:39 +0000 (00:08 +0000)
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.

defs.h
printsiginfo.c
syscall.c
tests/ptrace.c

diff --git a/defs.h b/defs.h
index 3a0c0636900f99c62583b68a6882df2f305559f6..1e95a65b5680095664a47d0eabb1ccb9c6eccd42 100644 (file)
--- 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);
 
index 1f4a825864ad1ec660083452a67dd3035864ce18..e92738edc4fe0c6ec39fd75cc799d4300f0f67c2 100644 (file)
@@ -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)
index 0488234eaa7fa73aabfaf4d92a0fe80edf1d6a8f..36f32799868edc9629f623ca620fb3f7c2c2e725 100644 (file)
--- 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 *
index 1dcfec3b652b7feb93c8071d5f61cf04e2369815..c046fa4859587fb95abd2b116b5b887f811615ad 100644 (file)
@@ -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);