Skip to content

Commit

Permalink
Update test apps
Browse files Browse the repository at this point in the history
  • Loading branch information
eliogovea committed Mar 8, 2024
1 parent fe3254a commit 1b07cf4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
17 changes: 9 additions & 8 deletions sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,33 @@ if (DNS_ENABLE_FUZZING)
)
endfunction()

dns_add_fuzzer(dns_decode_fuzzer dns_decode_fuzzer.cpp)
dns_add_fuzzer(dns_name_fuzzer dns_name_fuzzer.cpp)
dns_add_fuzzer(${PROJECT_NAME}_fuzzer_decode dns_fuzzer_decode.cpp)
dns_add_fuzzer(${PROJECT_NAME}_fuzzer_name dns_fuzzer_name.cpp)

endif (DNS_ENABLE_FUZZING)


# apps

add_executable(dns_resolver_testapp)
add_executable(${PROJECT_NAME}_testapp_resolver)

target_sources(
dns_resolver_testapp
PRIVATE dns_resolver_testapp.cpp
${PROJECT_NAME}_testapp_resolver
PRIVATE dns_testapp_resolver.cpp
)

target_link_libraries(
dns_resolver_testapp
${PROJECT_NAME}_testapp_resolver
PRIVATE ${PROJECT_NAME}_static
)

# TODO

# install

include(GNUInstallDirs)

install(
TARGETS ${PROJECT_NAME}_static
${PROJECT_NAME}_testapp_resolver
EXPORT ${PROJECT_NAME}
COMPONENT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -128,6 +127,8 @@ install(

install(
TARGETS ${PROJECT_NAME}_unittest
${PROJECT_NAME}_fuzzer_decode
${PROJECT_NAME}_fuzzer_name
COMPONENT ${PROJECT_NAME}
CONFIGURATIONS Debug
EXPORT ${PROJECT_NAME}
Expand Down
File renamed without changes.
15 changes: 10 additions & 5 deletions sources/dns_name_fuzzer.cpp → sources/dns_fuzzer_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <span>
#include <vector>

#include <iostream>

#include "dns_name.hpp"

extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
Expand All @@ -13,16 +15,19 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
return 0;
}

msg_idx = *reinterpret_cast<uint16_t const*>(data); // NOLINT
msg_idx = (msg_idx << 8) | *data;
data++;
size--;

data += sizeof(msg_idx);
size -= sizeof(msg_idx);
msg_idx = (msg_idx << 8) | *data;
data++;
size--;

if (size < msg_idx) {
if (size <= msg_idx) {
return 0;
}

std::vector<std::uint8_t> output(size);
auto output = std::vector<uint8_t>(size);
DNS::UnpackName(std::span{data, size}, msg_idx, output);

return 0;
Expand Down
File renamed without changes.

0 comments on commit 1b07cf4

Please sign in to comment.