2 * cryptsetup LUKS1, FileVault, BitLocker fuzz target
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #define FILESIZE (16777216)
21 #include "src/cryptsetup.h"
23 #include "luks1/luks.h"
24 #include "crypto_backend/crypto_backend.h"
25 #include "FuzzerInterface.h"
27 void empty_log(int level, const char *msg, void *usrptr) {}
29 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
31 struct crypt_device *cd = NULL;
32 char name[] = "/tmp/test-script-fuzz.XXXXXX";
34 fd = mkostemp(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC);
36 err(EXIT_FAILURE, "mkostemp() failed");
39 if (ftruncate(fd, FILESIZE) == -1)
42 if (write_buffer(fd, data, size) != (ssize_t) size)
45 crypt_set_log_callback(NULL, empty_log, NULL);
47 if (crypt_init(&cd, name) == 0) {
48 r = crypt_load(cd, CRYPT_LUKS1, NULL);
52 r = crypt_load(cd, CRYPT_FVAULT2, NULL);
56 (void) crypt_load(cd, CRYPT_BITLK, NULL);