Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/user/testbin/badcall/bad_ioctl.c
734 views
1
/*
2
* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
3
* The President and Fellows of Harvard College.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the University nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*/
29
30
/*
31
* ioctl
32
*/
33
34
#include <sys/types.h>
35
#include <sys/ioctl.h>
36
#include <unistd.h>
37
#include <stdio.h>
38
#include <errno.h>
39
40
#include "config.h"
41
#include "test.h"
42
43
static
44
void
45
one_ioctl_badbuf(int fd, int code, const char *codename,
46
void *ptr, const char *ptrdesc)
47
{
48
char desc[128];
49
int rv;
50
51
snprintf(desc, sizeof(desc), "ioctl %s with %s", codename, ptrdesc);
52
rv = ioctl(fd, code, ptr);
53
report_test(rv, errno, EFAULT, desc);
54
}
55
56
static
57
void
58
any_ioctl_badbuf(int fd, int code, const char *codename)
59
{
60
one_ioctl_badbuf(fd, code, codename, NULL, "NULL pointer");
61
one_ioctl_badbuf(fd, code, codename, INVAL_PTR, "invalid pointer");
62
one_ioctl_badbuf(fd, code, codename, KERN_PTR, "kernel pointer");
63
}
64
65
#define IOCTL(fd, sym) any_ioctl_badbuf(fd, sym, #sym)
66
67
static
68
void
69
ioctl_badbuf(void)
70
{
71
/*
72
* Since we don't actually define any ioctls, this code won't
73
* actually run. But if you do define ioctls, turn these tests
74
* on for those that actually use the data buffer argument for
75
* anything.
76
*/
77
78
/* IOCTL(STDIN_FILENO, TIOCGETA); */
79
80
81
/* suppress gcc warning */
82
(void)any_ioctl_badbuf;
83
}
84
85
static
86
void
87
ioctl_badcode(void)
88
{
89
int rv;
90
rv = ioctl(STDIN_FILENO, NONEXIST_IOCTL, NULL);
91
report_test(rv, errno, EIOCTL, "invalid ioctl");
92
}
93
94
void
95
test_ioctl(void)
96
{
97
test_ioctl_fd();
98
99
/* Since we don't actually define any ioctls, this is not meaningful */
100
ioctl_badcode();
101
ioctl_badbuf();
102
}
103
104