test_file_init.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <test.h>
23 
24 void
25 bfelf_loader_ut::test_bfelf_file_init_success()
26 {
27  bfelf_file_t ef;
28  auto &&data = get_test();
29  auto &&buff = std::get<0>(data);
30  auto &&size = std::get<1>(data);
31 
32  auto ret = bfelf_file_init(buff.get(), size, &ef);
33  this->expect_true(ret == BFELF_SUCCESS);
34 }
35 
36 void
37 bfelf_loader_ut::test_bfelf_file_init_invalid_file_arg()
38 {
39  bfelf_file_t ef;
40  auto &&data = get_test();
41  auto &&size = std::get<1>(data);
42 
43  auto ret = bfelf_file_init(nullptr, size, &ef);
45 }
46 
47 void
48 bfelf_loader_ut::test_bfelf_file_init_invalid_file_size_arg()
49 {
50  bfelf_file_t ef;
51  auto &&data = get_test();
52  auto &&buff = std::get<0>(data);
53 
54  auto ret = bfelf_file_init(buff.get(), 0, &ef);
56 }
57 
58 void
59 bfelf_loader_ut::test_bfelf_file_init_invalid_elf_file()
60 {
61  auto &&data = get_test();
62  auto &&buff = std::get<0>(data);
63  auto &&size = std::get<1>(data);
64 
65  auto ret = bfelf_file_init(buff.get(), size, nullptr);
67 }
68 
69 void
70 bfelf_loader_ut::test_bfelf_file_init_invalid_magic_0()
71 {
72  bfelf_file_t ef;
73  auto &&data = get_test();
74  auto &&buff = std::get<0>(data);
75  auto &&size = std::get<1>(data);
76  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
77 
78  test->header.e_ident[bfei_mag0] = 0;
79 
80  auto ret = bfelf_file_init(buff.get(), size, &ef);
82 }
83 
84 void
85 bfelf_loader_ut::test_bfelf_file_init_invalid_magic_1()
86 {
87  bfelf_file_t ef;
88  auto &&data = get_test();
89  auto &&buff = std::get<0>(data);
90  auto &&size = std::get<1>(data);
91  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
92 
93  test->header.e_ident[bfei_mag1] = 0;
94 
95  auto ret = bfelf_file_init(buff.get(), size, &ef);
97 }
98 
99 void
100 bfelf_loader_ut::test_bfelf_file_init_invalid_magic_2()
101 {
102  bfelf_file_t ef;
103  auto &&data = get_test();
104  auto &&buff = std::get<0>(data);
105  auto &&size = std::get<1>(data);
106  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
107 
108  test->header.e_ident[bfei_mag2] = 0;
109 
110  auto ret = bfelf_file_init(buff.get(), size, &ef);
112 }
113 
114 void
115 bfelf_loader_ut::test_bfelf_file_init_invalid_magic_3()
116 {
117  bfelf_file_t ef;
118  auto &&data = get_test();
119  auto &&buff = std::get<0>(data);
120  auto &&size = std::get<1>(data);
121  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
122 
123  test->header.e_ident[bfei_mag3] = 0;
124 
125  auto ret = bfelf_file_init(buff.get(), size, &ef);
127 }
128 
129 void
130 bfelf_loader_ut::test_bfelf_file_init_invalid_class()
131 {
132  bfelf_file_t ef;
133  auto &&data = get_test();
134  auto &&buff = std::get<0>(data);
135  auto &&size = std::get<1>(data);
136  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
137 
138  test->header.e_ident[bfei_class] = 0x4;
139 
140  auto ret = bfelf_file_init(buff.get(), size, &ef);
142 }
143 
144 void
145 bfelf_loader_ut::test_bfelf_file_init_invalid_data()
146 {
147  bfelf_file_t ef;
148  auto &&data = get_test();
149  auto &&buff = std::get<0>(data);
150  auto &&size = std::get<1>(data);
151  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
152 
153  test->header.e_ident[bfei_data] = 0x8;
154 
155  auto ret = bfelf_file_init(buff.get(), size, &ef);
157 }
158 
159 void
160 bfelf_loader_ut::test_bfelf_file_init_invalid_ident_version()
161 {
162  bfelf_file_t ef;
163  auto &&data = get_test();
164  auto &&buff = std::get<0>(data);
165  auto &&size = std::get<1>(data);
166  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
167 
168  test->header.e_ident[bfei_version] = 0x15;
169 
170  auto ret = bfelf_file_init(buff.get(), size, &ef);
172 }
173 
174 void
175 bfelf_loader_ut::test_bfelf_file_init_invalid_osabi()
176 {
177  bfelf_file_t ef;
178  auto &&data = get_test();
179  auto &&buff = std::get<0>(data);
180  auto &&size = std::get<1>(data);
181  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
182 
183  test->header.e_ident[bfei_osabi] = 0x16;
184 
185  auto ret = bfelf_file_init(buff.get(), size, &ef);
187 }
188 
189 void
190 bfelf_loader_ut::test_bfelf_file_init_invalid_abiversion()
191 {
192  bfelf_file_t ef;
193  auto &&data = get_test();
194  auto &&buff = std::get<0>(data);
195  auto &&size = std::get<1>(data);
196  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
197 
198  test->header.e_ident[bfei_abiversion] = 0x23;
199 
200  auto ret = bfelf_file_init(buff.get(), size, &ef);
202 }
203 
204 void
205 bfelf_loader_ut::test_bfelf_file_init_invalid_type()
206 {
207  bfelf_file_t ef;
208  auto &&data = get_test();
209  auto &&buff = std::get<0>(data);
210  auto &&size = std::get<1>(data);
211  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
212 
213  test->header.e_type = 0xDEAD;
214 
215  auto ret = bfelf_file_init(buff.get(), size, &ef);
217 }
218 
219 void
220 bfelf_loader_ut::test_bfelf_file_init_invalid_machine()
221 {
222  bfelf_file_t ef;
223  auto &&data = get_test();
224  auto &&buff = std::get<0>(data);
225  auto &&size = std::get<1>(data);
226  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
227 
228  test->header.e_machine = 0xDEAD;
229 
230  auto ret = bfelf_file_init(buff.get(), size, &ef);
232 }
233 
234 void
235 bfelf_loader_ut::test_bfelf_file_init_invalid_version()
236 {
237  bfelf_file_t ef;
238  auto &&data = get_test();
239  auto &&buff = std::get<0>(data);
240  auto &&size = std::get<1>(data);
241  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
242 
243  test->header.e_version = 0xDEAD;
244 
245  auto ret = bfelf_file_init(buff.get(), size, &ef);
247 }
248 
249 void
250 bfelf_loader_ut::test_bfelf_file_init_invalid_flags()
251 {
252  bfelf_file_t ef;
253  auto &&data = get_test();
254  auto &&buff = std::get<0>(data);
255  auto &&size = std::get<1>(data);
256  auto &&test = reinterpret_cast<bfelf_test *>(buff.get());
257 
258  test->header.e_flags = 0xDEAD;
259 
260  auto ret = bfelf_file_init(buff.get(), size, &ef);
262 }
#define BFELF_ERROR_INVALID_ARG
Definition: error_codes.h:81
int64_t unsigned long void * data
#define BFELF_ERROR_UNSUPPORTED_FILE
Definition: error_codes.h:85
constexpr const auto size
bfelf_ehdr header
Definition: test_elf.h:122
#define BFELF_SUCCESS
Definition: error_codes.h:80
#define BFELF_ERROR_INVALID_SIGNATURE
Definition: error_codes.h:84
#define expect_true(a)