1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 3 #include "device-internal.h" 4 #include "device-private.h" 5 #include "fd-util.h" 6 #include "fs-util.h" 7 #include "fuzz.h" 8 #include "tmpfile-util.h" 9 LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)10int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 11 _cleanup_(sd_device_unrefp) sd_device *dev = NULL; 12 _cleanup_(unlink_tempfilep) char filename[] = "/tmp/fuzz-udev-database.XXXXXX"; 13 _cleanup_fclose_ FILE *f = NULL; 14 15 if (!getenv("SYSTEMD_LOG_LEVEL")) 16 log_set_max_level(LOG_CRIT); 17 18 assert_se(fmkostemp_safe(filename, "r+", &f) == 0); 19 if (size != 0) 20 assert_se(fwrite(data, size, 1, f) == 1); 21 22 fflush(f); 23 assert_se(device_new_aux(&dev) >= 0); 24 (void) device_read_db_internal_filename(dev, filename); 25 return 0; 26 } 27