Skip to content

Commit

Permalink
Fix fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
vldmkr committed Feb 13, 2024
1 parent 1fceb4c commit ae9f33a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 12 additions & 7 deletions fuzzing/extra/TxParser.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -Werror -Wall -Wextra -Wno-unused-function -DFUZZ -pedantic -g -O0"
)

set(BOLOS_SDK $ENV{BOLOS_SDK})

add_library(txparser SHARED
${CMAKE_CURRENT_SOURCE_DIR}/../src/bcs/init.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/bcs/decoder.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/bcs/utf8.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/common/bip32.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/common/varint.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/common/read.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/common/write.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/common/buffer.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/common/format.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/transaction/utils.c
${CMAKE_CURRENT_SOURCE_DIR}/../src/transaction/deserialize.c
${BOLOS_SDK}/lib_standard_app/format.c
${BOLOS_SDK}/lib_standard_app/buffer.c
${BOLOS_SDK}/lib_standard_app/varint.c
${BOLOS_SDK}/lib_standard_app/read.c
${BOLOS_SDK}/lib_standard_app/write.c
${BOLOS_SDK}/lib_standard_app/bip32.c
)

set_target_properties(txparser PROPERTIES SOVERSION 1)

target_include_directories(txparser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../src)
target_include_directories(txparser PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../src
${BOLOS_SDK}/lib_standard_app
)
8 changes: 5 additions & 3 deletions fuzzing/fuzz_tx_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

extern "C" {
#include "bcs/init.h"
#include "common/buffer.h"
#include "common/format.h"
#include "buffer.h"
#include "format.h"
#include "transaction/deserialize.h"
#include "transaction/utils.h"
#include "transaction/types.h"
}

#define DEBUG 0

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
buffer_t buf = {.ptr = data, .size = size, .offset = 0};
transaction_t tx;
Expand All @@ -21,7 +23,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
transaction_init(&tx);
status = transaction_deserialize(&buf, &tx);

if (status == PARSING_OK && tx.tx_variant == TX_RAW &&
if (DEBUG && status == PARSING_OK && tx.tx_variant == TX_RAW &&
tx.payload_variant == PAYLOAD_ENTRY_FUNCTION) {
printf("\nTransaction size: %lu\n", size);
printf("chain_id: %d\n", tx.chain_id);
Expand Down

0 comments on commit ae9f33a

Please sign in to comment.