/src/u-boot/test/fuzz/btrfs.c
Line | Count | Source |
1 | | /* Copyright 2026 Google LLC |
2 | | * |
3 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | * you may not use this file except in compliance with the License. |
5 | | * You may obtain a copy of the License at |
6 | | * |
7 | | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | | * |
9 | | * Unless required by applicable law or agreed to in writing, software |
10 | | * distributed under the License is distributed on an "AS IS" BASIS, |
11 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | * See the License for the specific language governing permissions and |
13 | | * limitations under the License. |
14 | | * |
15 | | * Fuzz test for BTRFS filesystem parser. |
16 | | */ |
17 | | |
18 | | #include <command.h> |
19 | | #include <os.h> |
20 | | #include <test/fuzz.h> |
21 | | |
22 | 0 | #define FUZZ_DISK_PATH "/tmp/fuzz_btrfs.img" |
23 | | |
24 | | static int fuzz_btrfs(const uint8_t *data, size_t size) |
25 | 0 | { |
26 | 0 | int fd; |
27 | |
|
28 | 0 | if (size < 512) |
29 | 0 | return 0; |
30 | | |
31 | 0 | fd = os_open(FUZZ_DISK_PATH, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC); |
32 | 0 | if (fd < 0) |
33 | 0 | return 0; |
34 | 0 | os_write(fd, data, size); |
35 | 0 | os_close(fd); |
36 | |
|
37 | 0 | run_command("host bind 0 " FUZZ_DISK_PATH, 0); |
38 | 0 | run_command("ls host 0:0 /", 0); |
39 | 0 | run_command("host unbind 0", 0); |
40 | |
|
41 | 0 | return 0; |
42 | 0 | } |
43 | | FUZZ_TEST(fuzz_btrfs, 0); |