2 * cryptsetup LUKS2 custom mutator fuzz target
4 * Copyright (C) 2022-2023 Daniel Zatovic <daniel.zatovic@gmail.com>
5 * Copyright (C) 2022-2023 Red Hat, Inc. All rights reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "LUKS2_plain_JSON.pb.h"
23 #include "plain_json_proto_to_luks2_converter.h"
24 #include "libfuzzer/libfuzzer_macro.h"
25 #include "FuzzerInterface.h"
28 #include <libcryptsetup.h>
34 DEFINE_PROTO_FUZZER(const json_proto::LUKS2_both_headers &headers) {
35 struct crypt_device *cd = NULL;
36 char name[] = "/tmp/test-proto-fuzz.XXXXXX";
37 int fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
40 err(EXIT_FAILURE, "mkostemp() failed");
42 json_proto::LUKS2ProtoConverter converter;
43 converter.convert(headers, fd);
45 if (crypt_init(&cd, name) == 0)
46 (void)crypt_load(cd, CRYPT_LUKS2, NULL);