diff options
| author | Greg Steuck <blackgnezdo@gmail.com> | 2018-11-30 11:55:51 -0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2018-11-30 19:55:51 +0000 |
| commit | d8988561c04c0244155309bdf701998b9fb98dd5 (patch) | |
| tree | 9d022f5c7cf53a78828ccb4bcb6823ac59e599fa | |
| parent | f0d4c650a3a689c859bfc34db06d1fab696ff31e (diff) | |
openbsd: repair pkg/csource_test
| -rw-r--r-- | executor/common_bsd.h | 93 | ||||
| -rw-r--r-- | executor/executor_bsd.h | 5 | ||||
| -rw-r--r-- | pkg/csource/csource_test.go | 4 | ||||
| -rw-r--r-- | pkg/csource/generated.go | 74 |
4 files changed, 79 insertions, 97 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h index a7fc5c8f5..be9fa4029 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -11,6 +11,50 @@ #if GOOS_openbsd +#define __syscall syscall + +#if SYZ_EXECUTOR || __NR_syz_open_pts + +#include <termios.h> +#include <util.h> + +static uintptr_t syz_open_pts(void) +{ + int master, slave; + + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) + return -1; + // Move the master fd up in order to reduce the chances of the fuzzer + // generating a call to close(2) with the same fd. + if (dup2(master, master + 100) != -1) + close(master); + return slave; +} + +#endif // SYZ_EXECUTOR || __NR_syz_open_pts + +#if SYZ_EXECUTOR || SYZ_TUN_ENABLE + +#include <fcntl.h> +#include <net/if_tun.h> +#include <sys/types.h> + +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. +#define SYZ_TUN_MAX_PACKET_SIZE 1000 + +// Maximum number of tun devices in the default install. +#define MAX_TUN 4 + +// All patterns are non-expanding given values < MAX_TUN. +#define TUN_IFACE "tap%d" +#define TUN_DEVICE "/dev/tap%d" + +#define LOCAL_IPV4 "172.20.%d.170" +#define LOCAL_IPV6 "fe80::%02hxaa" + static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv; @@ -56,55 +100,6 @@ static void execute_command(bool panic, const char* format, ...) } } -#define __syscall syscall - -#if SYZ_EXECUTOR || __NR_syz_open_pts - -#if defined(__OpenBSD__) -#include <termios.h> -#include <util.h> -#else -// Needed when compiling on Linux. -#include <pty.h> -#endif // defined(__OpenBSD__) - -static uintptr_t syz_open_pts(void) -{ - int master, slave; - - if (openpty(&master, &slave, NULL, NULL, NULL) == -1) - return -1; - // Move the master fd up in order to reduce the chances of the fuzzer - // generating a call to close(2) with the same fd. - if (dup2(master, master + 100) != -1) - close(master); - return slave; -} - -#endif // SYZ_EXECUTOR || __NR_syz_open_pts - -#if SYZ_EXECUTOR || SYZ_TUN_ENABLE - -#include <fcntl.h> -#include <net/if_tun.h> -#include <sys/types.h> - -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. -#define SYZ_TUN_MAX_PACKET_SIZE 1000 - -// Maximum number of tun devices in the default install. -#define MAX_TUN 4 - -// All patterns are non-expanding given values < MAX_TUN. -#define TUN_IFACE "tap%d" -#define TUN_DEVICE "/dev/tap%d" - -#define LOCAL_IPV4 "172.20.%d.170" -#define LOCAL_IPV6 "fe80::%02hxaa" - static void initialize_tun(int tun_id) { #if SYZ_EXECUTOR diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h index 3612e2569..7119a3992 100644 --- a/executor/executor_bsd.h +++ b/executor/executor_bsd.h @@ -10,11 +10,6 @@ #include <sys/types.h> #include <unistd.h> -#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) -// This is just so that "make executor TARGETOS=freebsd/netbsd" works on linux. -#define __syscall syscall -#endif - static void os_init(int argc, char** argv, void* data, size_t data_size) { #if GOOS_openbsd diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go index 9743b6356..c8246deae 100644 --- a/pkg/csource/csource_test.go +++ b/pkg/csource/csource_test.go @@ -18,10 +18,6 @@ import ( ) func TestGenerate(t *testing.T) { - switch runtime.GOOS { - case "openbsd": - t.Skipf("broken on %v", runtime.GOOS) - } t.Parallel() for _, target := range prog.AllTargets() { target := target diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 5faa7735b..d399fb405 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -408,6 +408,41 @@ void child() #if GOOS_openbsd +#define __syscall syscall + +#if SYZ_EXECUTOR || __NR_syz_open_pts + +#include <termios.h> +#include <util.h> + +static uintptr_t syz_open_pts(void) +{ + int master, slave; + + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) + return -1; + if (dup2(master, master + 100) != -1) + close(master); + return slave; +} + +#endif + +#if SYZ_EXECUTOR || SYZ_TUN_ENABLE + +#include <fcntl.h> +#include <net/if_tun.h> +#include <sys/types.h> + +static int tunfd = -1; +#define SYZ_TUN_MAX_PACKET_SIZE 1000 +#define MAX_TUN 4 +#define TUN_IFACE "tap%d" +#define TUN_DEVICE "/dev/tap%d" + +#define LOCAL_IPV4 "172.20.%d.170" +#define LOCAL_IPV6 "fe80::%02hxaa" + static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv; @@ -450,45 +485,6 @@ static void execute_command(bool panic, const char* format, ...) } } -#define __syscall syscall - -#if SYZ_EXECUTOR || __NR_syz_open_pts - -#if defined(__OpenBSD__) -#include <termios.h> -#include <util.h> -#else -#include <pty.h> -#endif - -static uintptr_t syz_open_pts(void) -{ - int master, slave; - - if (openpty(&master, &slave, NULL, NULL, NULL) == -1) - return -1; - if (dup2(master, master + 100) != -1) - close(master); - return slave; -} - -#endif - -#if SYZ_EXECUTOR || SYZ_TUN_ENABLE - -#include <fcntl.h> -#include <net/if_tun.h> -#include <sys/types.h> - -static int tunfd = -1; -#define SYZ_TUN_MAX_PACKET_SIZE 1000 -#define MAX_TUN 4 -#define TUN_IFACE "tap%d" -#define TUN_DEVICE "/dev/tap%d" - -#define LOCAL_IPV4 "172.20.%d.170" -#define LOCAL_IPV6 "fe80::%02hxaa" - static void initialize_tun(int tun_id) { #if SYZ_EXECUTOR |
