aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-declextract/testdata/scopes.c
blob: 57809ae3dd68a8c157c95c65f280b2e3a86200d6 (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
// Copyright 2024 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.

#include "include/fs.h"
#include "include/syscall.h"
#include "include/uapi/file_operations.h"

#define LARGE_UINT (1ull<<63) // this is supposed to overflow int64
#define LARGE_SINT (20ll<<63) // this is supposed to overflow uint64

static int scopes_helper(long cmd, long aux) {
	switch (cmd) {
	case FOO_IOCTL7:
		return alloc_fd();
	case FOO_IOCTL8:
		__fget_light(aux);
		break;
	case LARGE_UINT:
	case LARGE_SINT:
		break;
	}
	return 0;
}

SYSCALL_DEFINE1(scopes0, int x, long cmd, long aux) {
	int tmp = 0;
	__fget_light(aux);
	switch (cmd) {
	case FOO_IOCTL1:
		__fget_light(x);
		break;
	case FOO_IOCTL2:
	case FOO_IOCTL3:
		tmp = alloc_fd();
		return tmp;
	case FOO_IOCTL4 ... FOO_IOCTL4 + 2:
		tmp++;
		break;
	case FOO_IOCTL7:
	case FOO_IOCTL8:
		tmp = scopes_helper(cmd, x);
		break;
	case 100 ... 102:
		tmp++;
		break;
	default:
		tmp = cmd;
		break;
	}
	return tmp;
}