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 /executor/common_bsd.h | |
| parent | f0d4c650a3a689c859bfc34db06d1fab696ff31e (diff) | |
openbsd: repair pkg/csource_test
Diffstat (limited to 'executor/common_bsd.h')
| -rw-r--r-- | executor/common_bsd.h | 93 |
1 files changed, 44 insertions, 49 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 |
