diff --git a/fuzz/C++/fuzz_XMLProfiles/fuzz_XMLProfiles.cxx b/fuzz/C++/fuzz_XMLProfiles/fuzz_XMLProfiles.cxx index c475e238af1..c5f953147f5 100644 --- a/fuzz/C++/fuzz_XMLProfiles/fuzz_XMLProfiles.cxx +++ b/fuzz/C++/fuzz_XMLProfiles/fuzz_XMLProfiles.cxx @@ -1,5 +1,4 @@ -#include -#include +#include #include "fuzz_utils.h" @@ -23,21 +22,7 @@ extern "C" int LLVMFuzzerTestOneInput( return EXIT_FAILURE; } - const char* filename = buf_to_file(data, size); - - if (filename == NULL) - { - return EXIT_FAILURE; - } - - // TODO change this to a func. taking buf + len (or C string) - // to avoid using `buf_to_file` - xmlparser::XMLProfileManager::loadXMLFile(filename); - - if (delete_file(filename) != 0) - { - return EXIT_FAILURE; - } + fastdds::dds::DomainParticipantFactory::get_instance()->load_XML_profiles_string(reinterpret_cast(data), size); return 0; } diff --git a/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.cxx b/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.cxx index 0a10810ac7c..56feebad706 100644 --- a/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.cxx +++ b/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.cxx @@ -32,64 +32,3 @@ extern "C" int ignore_stdout( return ret; } - -extern "C" int delete_file( - const char* pathname) -{ - int ret = unlink(pathname); - if (ret == -1) - { - warn("failed to delete \"%s\"", pathname); - } - - free((void*)pathname); - - return ret; -} - -extern "C" char* buf_to_file( - const uint8_t* buf, - size_t size) -{ - char* pathname = strdup("/dev/shm/fuzz-XXXXXX"); - if (pathname == NULL) - { - return NULL; - } - - int fd = mkstemp(pathname); - if (fd == -1) - { - warn("mkstemp(\"%s\")", pathname); - free(pathname); - return NULL; - } - - size_t pos = 0; - while (pos < size) - { - int nbytes = write(fd, &buf[pos], size - pos); - if (nbytes <= 0) - { - if (nbytes == -1 && errno == EINTR) - { - continue; - } - warn("write"); - goto err; - } - pos += nbytes; - } - - if (close(fd) == -1) - { - warn("close"); - goto err; - } - - return pathname; - -err: - delete_file(pathname); - return NULL; -} \ No newline at end of file diff --git a/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.h b/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.h index 37b484eb286..193e635b733 100644 --- a/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.h +++ b/fuzz/C++/fuzz_XMLProfiles/fuzz_utils.h @@ -13,21 +13,5 @@ extern "C" int ignore_stdout( void); -// Delete the file passed as argument and free the associated buffer. This -// function is meant to be called on buf_to_file return value. -// -// Return 0 on success, -1 otherwise. -extern "C" int delete_file( - const char* pathname); - -// Write the data provided in buf to a new temporary file. This function is -// meant to be called by LLVMFuzzerTestOneInput() for fuzz targets that only -// take file names (and not data) as input. -// -// Return the path of the newly created file or NULL on error. The caller should -// eventually free the returned buffer (see delete_file). -extern "C" char* buf_to_file( - const uint8_t* buf, - size_t size); #endif // FUZZ_UTILS_H_ \ No newline at end of file