openbsd: repair pkg/csource_test

This commit is contained in:
Greg Steuck 2018-11-30 11:55:51 -08:00 committed by Dmitry Vyukov
parent f0d4c650a3
commit d8988561c0
4 changed files with 79 additions and 97 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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