aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-06-13 17:21:33 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-06-13 17:21:33 +0200
commit47be383ea0d2fd1008fa37be6695634fe17ad805 (patch)
tree7843b132a242f4ecc0cfdebe6ad2d7f6d30ece53
parent88ccde80d3ea11c2e00c98ba833824ec565edcc3 (diff)
executor: fix clang-tidy warnings
A single check is enabled for now (misc-definitions-in-headers). But it's always fixable and found 2 bugs in csource.
-rw-r--r--Makefile6
-rw-r--r--csource/common.go30
-rw-r--r--csource/csource.go10
-rw-r--r--executor/common.h30
-rw-r--r--executor/syscalls.h6
-rw-r--r--sysgen/syscallnr.go2
6 files changed, 48 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 0fa742851..52ca83134 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ ifeq ($(NOSTATIC), 0)
STATIC_FLAG=-static
endif
-.PHONY: all format clean manager fuzzer executor execprog mutate prog2c stress extract generate repro
+.PHONY: all format tidy clean manager fuzzer executor execprog mutate prog2c stress extract generate repro
all:
go install ./syz-manager ./syz-fuzzer
@@ -65,6 +65,10 @@ format:
go fmt ./...
clang-format --style=file -i executor/*.cc executor/*.h tools/kcovtrace/*.c
+# A single check is enabled for now. But it's always fixable and proved to be useful.
+tidy:
+ clang-tidy -quiet -header-filter=.* -checks=-*,misc-definitions-in-headers -warnings-as-errors=* executor/*.cc
+
presubmit:
$(MAKE) generate
go generate ./...
diff --git a/csource/common.go b/csource/common.go
index 242df15a1..5e241092a 100644
--- a/csource/common.go
+++ b/csource/common.go
@@ -138,7 +138,7 @@ const int kErrorStatus = 68;
defined(SYZ_HANDLE_SEGV) || defined(SYZ_TUN_ENABLE) || defined(SYZ_SANDBOX_NAMESPACE) || \
defined(SYZ_SANDBOX_SETUID) || defined(SYZ_SANDBOX_NONE) || defined(SYZ_FAULT_INJECTION) || \
defined(__NR_syz_kvm_setup_cpu)
-__attribute__((noreturn)) void doexit(int status)
+__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
@@ -155,7 +155,7 @@ __attribute__((noreturn)) void doexit(int status)
#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)) || defined(SYZ_USE_TMP_DIR) || \
defined(SYZ_TUN_ENABLE) || defined(SYZ_SANDBOX_NAMESPACE) || defined(SYZ_SANDBOX_SETUID) || \
defined(SYZ_FAULT_INJECTION) || defined(__NR_syz_kvm_setup_cpu)
-__attribute__((noreturn)) void fail(const char* msg, ...)
+__attribute__((noreturn)) static void fail(const char* msg, ...)
{
int e = errno;
fflush(stdout);
@@ -169,7 +169,7 @@ __attribute__((noreturn)) void fail(const char* msg, ...)
#endif
#if defined(SYZ_EXECUTOR)
-__attribute__((noreturn)) void error(const char* msg, ...)
+__attribute__((noreturn)) static void error(const char* msg, ...)
{
fflush(stdout);
va_list args;
@@ -182,7 +182,7 @@ __attribute__((noreturn)) void error(const char* msg, ...)
#endif
#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
-__attribute__((noreturn)) void exitf(const char* msg, ...)
+__attribute__((noreturn)) static void exitf(const char* msg, ...)
{
int e = errno;
fflush(stdout);
@@ -198,7 +198,7 @@ __attribute__((noreturn)) void exitf(const char* msg, ...)
#if defined(SYZ_EXECUTOR) || defined(SYZ_DEBUG)
static int flag_debug;
-void debug(const char* msg, ...)
+static void debug(const char* msg, ...)
{
if (!flag_debug)
return;
@@ -227,8 +227,8 @@ void debug(const char* msg, ...)
#endif
#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV)
-__thread int skip_segv;
-__thread jmp_buf segv_env;
+static __thread int skip_segv;
+static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* uctx)
{
@@ -324,7 +324,7 @@ static void execute_command(const char* format, ...)
va_end(args);
}
-int tunfd = -1;
+static int tunfd = -1;
#define SYZ_TUN_MAX_PACKET_SIZE 1000
@@ -394,7 +394,7 @@ static void setup_tun(uint64_t pid, bool enable_tun)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_TUN_ENABLE) && (defined(__NR_syz_extract_tcp_res) || defined(SYZ_REPEAT)))
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_TUN_ENABLE) && (defined(__NR_syz_extract_tcp_res) || defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)))
static int read_tun(char* data, int size)
{
int rv = read(tunfd, data, size);
@@ -421,17 +421,17 @@ static void debug_dump_data(const char* data, int length)
}
#endif
-#if defined(SYZ_EXECUTOR) || defined(SYZ_USE_CHECKSUMS) || defined(__NR_syz_test)
+#if defined(SYZ_EXECUTOR) || defined(SYZ_USE_CHECKSUMS)
struct csum_inet {
uint32_t acc;
};
-void csum_inet_init(struct csum_inet* csum)
+static void csum_inet_init(struct csum_inet* csum)
{
csum->acc = 0;
}
-void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length)
+static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length)
{
if (length == 0)
return;
@@ -447,7 +447,7 @@ void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length
csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16);
}
-uint16_t csum_inet_digest(struct csum_inet* csum)
+static uint16_t csum_inet_digest(struct csum_inet* csum)
{
return ~csum->acc;
}
@@ -467,8 +467,8 @@ static uintptr_t syz_emit_ethernet(uintptr_t a0, uintptr_t a1)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_TUN_ENABLE))
-void flush_tun()
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT) && defined(SYZ_TUN_ENABLE))
+static void flush_tun()
{
char data[SYZ_TUN_MAX_PACKET_SIZE];
while (read_tun(&data[0], sizeof(data)) != -1)
diff --git a/csource/csource.go b/csource/csource.go
index 6caac68bf..db610ce2e 100644
--- a/csource/csource.go
+++ b/csource/csource.go
@@ -175,6 +175,10 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) {
func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
if !opts.Threaded && !opts.Collide {
fmt.Fprintf(w, "void %v()\n{\n", name)
+ if opts.Debug {
+ // Use debug to avoid: error: ‘debug’ defined but not used.
+ fmt.Fprintf(w, "\tdebug(\"%v\\n\");\n", name)
+ }
if opts.Repro {
fmt.Fprintf(w, "\tsyscall(SYS_write, 1, \"executing program\\n\", strlen(\"executing program\\n\"));\n")
}
@@ -198,6 +202,10 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
fmt.Fprintf(w, "\tlong i;\n")
fmt.Fprintf(w, "\tpthread_t th[%v];\n", 2*len(calls))
fmt.Fprintf(w, "\n")
+ if opts.Debug {
+ // Use debug to avoid: error: ‘debug’ defined but not used.
+ fmt.Fprintf(w, "\tdebug(\"%v\\n\");\n", name)
+ }
if opts.Repro {
fmt.Fprintf(w, "\tsyscall(SYS_write, 1, \"executing program\\n\", strlen(\"executing program\\n\"));\n")
}
@@ -387,7 +395,7 @@ func preprocessCommonHeader(opts Options, handled map[string]int, useBitmasks, u
if useBitmasks {
defines = append(defines, "SYZ_USE_BITMASKS")
}
- if useBitmasks {
+ if useChecksums {
defines = append(defines, "SYZ_USE_CHECKSUMS")
}
switch opts.Sandbox {
diff --git a/executor/common.h b/executor/common.h
index 6a166b6dd..8ced8313b 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -148,7 +148,7 @@ const int kErrorStatus = 68;
// And this does not work as well. _exit has own handling of failing exit_group
// in the form of HLT instruction, it will divert control flow from our loop.
// So call the syscall directly.
-__attribute__((noreturn)) void doexit(int status)
+__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
@@ -167,7 +167,7 @@ __attribute__((noreturn)) void doexit(int status)
defined(SYZ_TUN_ENABLE) || defined(SYZ_SANDBOX_NAMESPACE) || defined(SYZ_SANDBOX_SETUID) || \
defined(SYZ_FAULT_INJECTION) || defined(__NR_syz_kvm_setup_cpu)
// logical error (e.g. invalid input program), use as an assert() alernative
-__attribute__((noreturn)) void fail(const char* msg, ...)
+__attribute__((noreturn)) static void fail(const char* msg, ...)
{
int e = errno;
fflush(stdout);
@@ -184,7 +184,7 @@ __attribute__((noreturn)) void fail(const char* msg, ...)
#if defined(SYZ_EXECUTOR)
// kernel error (e.g. wrong syscall return value)
-__attribute__((noreturn)) void error(const char* msg, ...)
+__attribute__((noreturn)) static void error(const char* msg, ...)
{
fflush(stdout);
va_list args;
@@ -198,7 +198,7 @@ __attribute__((noreturn)) void error(const char* msg, ...)
#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT))
// just exit (e.g. due to temporal ENOMEM error)
-__attribute__((noreturn)) void exitf(const char* msg, ...)
+__attribute__((noreturn)) static void exitf(const char* msg, ...)
{
int e = errno;
fflush(stdout);
@@ -214,7 +214,7 @@ __attribute__((noreturn)) void exitf(const char* msg, ...)
#if defined(SYZ_EXECUTOR) || defined(SYZ_DEBUG)
static int flag_debug;
-void debug(const char* msg, ...)
+static void debug(const char* msg, ...)
{
if (!flag_debug)
return;
@@ -243,8 +243,8 @@ void debug(const char* msg, ...)
#endif
#if defined(SYZ_EXECUTOR) || defined(SYZ_HANDLE_SEGV)
-__thread int skip_segv;
-__thread jmp_buf segv_env;
+static __thread int skip_segv;
+static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* uctx)
{
@@ -349,7 +349,7 @@ static void execute_command(const char* format, ...)
va_end(args);
}
-int tunfd = -1;
+static int tunfd = -1;
// We just need this to be large enough to hold headers that we parse (ethernet/ip/tcp).
// Rest of the packet (if any) will be silently truncated which is fine.
@@ -425,7 +425,7 @@ static void setup_tun(uint64_t pid, bool enable_tun)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_TUN_ENABLE) && (defined(__NR_syz_extract_tcp_res) || defined(SYZ_REPEAT)))
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_TUN_ENABLE) && (defined(__NR_syz_extract_tcp_res) || defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT)))
static int read_tun(char* data, int size)
{
int rv = read(tunfd, data, size);
@@ -452,17 +452,17 @@ static void debug_dump_data(const char* data, int length)
}
#endif
-#if defined(SYZ_EXECUTOR) || defined(SYZ_USE_CHECKSUMS) || defined(__NR_syz_test)
+#if defined(SYZ_EXECUTOR) || defined(SYZ_USE_CHECKSUMS)
struct csum_inet {
uint32_t acc;
};
-void csum_inet_init(struct csum_inet* csum)
+static void csum_inet_init(struct csum_inet* csum)
{
csum->acc = 0;
}
-void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length)
+static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length)
{
if (length == 0)
return;
@@ -478,7 +478,7 @@ void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length
csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16);
}
-uint16_t csum_inet_digest(struct csum_inet* csum)
+static uint16_t csum_inet_digest(struct csum_inet* csum)
{
return ~csum->acc;
}
@@ -499,8 +499,8 @@ static uintptr_t syz_emit_ethernet(uintptr_t a0, uintptr_t a1)
}
#endif
-#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_TUN_ENABLE))
-void flush_tun()
+#if defined(SYZ_EXECUTOR) || (defined(SYZ_REPEAT) && defined(SYZ_WAIT_REPEAT) && defined(SYZ_TUN_ENABLE))
+static void flush_tun()
{
char data[SYZ_TUN_MAX_PACKET_SIZE];
while (read_tun(&data[0], sizeof(data)) != -1)
diff --git a/executor/syscalls.h b/executor/syscalls.h
index e6ba186b6..9662d7718 100644
--- a/executor/syscalls.h
+++ b/executor/syscalls.h
@@ -15,7 +15,7 @@ struct call_t {
};
#if defined(__x86_64__) || 0
-call_t syscalls[] = {
+static call_t syscalls[] = {
{"accept", 43},
{"accept$alg", 43},
{"accept$ax25", 43},
@@ -1524,7 +1524,7 @@ call_t syscalls[] = {
#endif
#if defined(__aarch64__) || 0
-call_t syscalls[] = {
+static call_t syscalls[] = {
{"accept", 202},
{"accept$alg", 202},
{"accept$ax25", 202},
@@ -3033,7 +3033,7 @@ call_t syscalls[] = {
#endif
#if defined(__ppc64__) || defined(__PPC64__) || defined(__powerpc64__) || 0
-call_t syscalls[] = {
+static call_t syscalls[] = {
{"accept", 330},
{"accept$alg", 330},
{"accept$ax25", 330},
diff --git a/sysgen/syscallnr.go b/sysgen/syscallnr.go
index 81244018c..0f2fa58a9 100644
--- a/sysgen/syscallnr.go
+++ b/sysgen/syscallnr.go
@@ -94,7 +94,7 @@ struct call_t {
{{range $arch := $.Archs}}
#if {{range $cdef := $arch.CARCH}}defined({{$cdef}}) || {{end}}0
-call_t syscalls[] = {
+static call_t syscalls[] = {
{{range $c := $arch.Calls}} {"{{$c.Name}}", {{$c.NR}}},
{{end}}
};