aboutsummaryrefslogtreecommitdiffstats
path: root/sys/openbsd/init_test.go
blob: 39e93a688b746a0bb32b30e99c84700769575279 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2019 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package openbsd_test

import (
	"fmt"
	"strings"
	"testing"

	"github.com/google/syzkaller/prog"
	_ "github.com/google/syzkaller/sys/openbsd/gen"
)

func TestSanitizeCall(t *testing.T) {
	target, err := prog.GetTarget("openbsd", "amd64")
	if err != nil {
		t.Fatal(err)
	}
	tests := []struct {
		input  string
		output string
	}{
		{
			`chflagsat(0x0, 0x0, 0x60004, 0x0)`,
			`chflagsat(0x0, 0x0, 0x0, 0x0)`,
		},
		{
			`fchflags(0x0, 0x60004)`,
			`fchflags(0x0, 0x0)`,
		},
		{
			`ioctl$BIOCSDIRFILT(0x0, 0xc0e04429, 0x0)`,
			`ioctl$BIOCSDIRFILT(0x0, 0x0, 0x0)`,
		},
		{
			// major=22, minor=232
			`mknodat(0x0, 0x0, 0x0, 0x16e8)`,
			`mknodat(0x0, 0x0, 0x0, 0x202)`,
		},
		{
			// major=22, minor=232
			`mknod(0x0, 0x0, 0x16e8)`,
			`mknod(0x0, 0x0, 0x202)`,
		},
		{
			// major=22, minor=0
			`mknod(0x0, 0x0, 0x1600)`,
			`mknod(0x0, 0x0, 0x1600)`,
		},
		{
			// major=4, minor=0
			`mknod(0x0, 0x0, 0x400)`,
			`mknod(0x0, 0x0, 0x400)`,
		},
		{
			// major=4, minor=1
			`mknod(0x0, 0x0, 0x401)`,
			`mknod(0x0, 0x0, 0x202)`,
		},
		{
			// major=4, minor=2
			`mknod(0x0, 0x0, 0x402)`,
			`mknod(0x0, 0x0, 0x202)`,
		},
		{
			// MCL_CURRENT | MCL_FUTURE
			`mlockall(0x3)`,
			`mlockall(0x1)`,
		},
		{
			// RLIMIT_DATA
			`setrlimit(0x2, &(0x7f0000cc0ff0)={0x0, 0x80000000})`,
			`setrlimit(0x2, &(0x7f0000cc0ff0)={0x60000000, 0x80000000})`,
		},
		{
			// RLIMIT_DATA
			`setrlimit(0x10000000000002, &(0x7f0000cc0ff0)={0x0, 0x80000000})`,
			`setrlimit(0x10000000000002, &(0x7f0000cc0ff0)={0x60000000, 0x80000000})`,
		},
		{
			// RLIMIT_STACK
			`setrlimit(0x3, &(0x7f0000cc0ff0)={0x1000000000, 0x1000000000})`,
			`setrlimit(0x3, &(0x7f0000cc0ff0)={0x100000, 0x100000})`,
		},
		{
			// RLIMIT_CPU
			`setrlimit(0x0, &(0x7f0000cc0ff0)={0x1, 0x1})`,
			`setrlimit(0x0, &(0x7f0000cc0ff0)={0x1, 0x1})`,
		},
	}
	for i, test := range tests {
		t.Run(fmt.Sprint(i), func(t *testing.T) {
			p, err := target.Deserialize([]byte(test.input), prog.Strict)
			if err != nil {
				t.Fatal(err)
			}
			got := strings.TrimSpace(string(p.Serialize()))
			want := strings.TrimSpace(test.output)
			if got != want {
				t.Fatalf("input:\n%v\ngot:\n%v\nwant:\n%s", test.input, got, want)
			}
		})
	}
}