From 49783dc8f2c8b2a312dd8faa50c53301a2a4243d Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 1 Nov 2018 20:51:05 -0400 Subject: [PATCH] strace: Gracefully handle invalid syscall numbers. OpenJDK 1.8 somehow manages to trigger this. Before this commit it would just attempt to read past the end of the vector, which of course segfaulted, which seems to imply nobody has run into this case before. --- src/bin/debug/strace/strace.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bin/debug/strace/strace.cpp b/src/bin/debug/strace/strace.cpp index a19fe0c9e6..25a436b55f 100644 --- a/src/bin/debug/strace/strace.cpp +++ b/src/bin/debug/strace/strace.cpp @@ -686,7 +686,12 @@ main(int argc, const char *const *argv) Team* team = it->second; MemoryReader& memoryReader = team->GetMemoryReader(); - int32 syscallNumber = message.post_syscall.syscall; + uint32 syscallNumber = message.post_syscall.syscall; + if (syscallNumber >= sSyscallVector.size()) { + fprintf(stderr, "%s: invalid syscall %" B_PRIu32 " attempted\n", + kCommandName, syscallNumber); + break; + } Syscall* syscall = sSyscallVector[syscallNumber]; if (stats)