Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Jun 11, 2024
1 parent 2e2f300 commit 19110a8
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 17 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cmake_policy(SET CMP0025 NEW)
cmake_policy(SET CMP0144 NEW)

set(HUNTER_STATUS_DEBUG ON)
set(HUNTER_TLS_VERIFY OFF)
set(HUNTER_TLS_VERIFY ON)

enable_testing()

Expand Down Expand Up @@ -65,6 +65,11 @@ if(ENABLE_FUZZING)
SET(ENABLE_SANITIZERS ON CACHE BOOL "Sanitizer automatically enabled" FORCE)
SET(CMAKE_BUILD_TYPE Debug)

add_definitions(-DENABLE_COVERAGE=1)
string(APPEND CMAKE_C_FLAGS " -fprofile-arcs -ftest-coverage")
string(APPEND CMAKE_CXX_FLAGS " -fprofile-arcs -ftest-coverage")
string(APPEND CMAKE_LINKER_FLAGS " -fprofile-arcs -ftest-coverage")

if (DEFINED ENV{FUZZ_LOGGING})
add_definitions(-DFUZZING_LOGGING)
message(FATAL_ERROR "Fuzz logging enabled")
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=26
# This is the `spec_version` field of `Runtime`
APPVERSION_N=1002005
# This is the patch version of this release
APPVERSION_P=0
APPVERSION_P=1
31 changes: 19 additions & 12 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,32 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
G_io_apdu_buffer[0] = 0x01;
#endif

G_io_apdu_buffer[1] = (LEDGER_MAJOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[2] = (LEDGER_MAJOR_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[1] = (LEDGER_MAJOR_VERSION >> 24) & 0xFF;
G_io_apdu_buffer[2] = (LEDGER_MAJOR_VERSION >> 16) & 0xFF;
G_io_apdu_buffer[3] = (LEDGER_MAJOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[4] = (LEDGER_MAJOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[3] = (LEDGER_MINOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[4] = (LEDGER_MINOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[5] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[6] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;
G_io_apdu_buffer[5] = (LEDGER_MINOR_VERSION >> 24) & 0xFF;
G_io_apdu_buffer[6] = (LEDGER_MINOR_VERSION >> 16) & 0xFF;
G_io_apdu_buffer[7] = (LEDGER_MINOR_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[8] = (LEDGER_MINOR_VERSION >> 0) & 0xFF;

G_io_apdu_buffer[9] = (LEDGER_PATCH_VERSION >> 24) & 0xFF;
G_io_apdu_buffer[10] = (LEDGER_PATCH_VERSION >> 16) & 0xFF;
G_io_apdu_buffer[11] = (LEDGER_PATCH_VERSION >> 8) & 0xFF;
G_io_apdu_buffer[12] = (LEDGER_PATCH_VERSION >> 0) & 0xFF;

// sdk won't pass the apdu message if device is locked
// keeping it for backwards compatibility
G_io_apdu_buffer[7] = 0;
G_io_apdu_buffer[13] = 0;

G_io_apdu_buffer[8] = (TARGET_ID >> 24) & 0xFF;
G_io_apdu_buffer[9] = (TARGET_ID >> 16) & 0xFF;
G_io_apdu_buffer[10] = (TARGET_ID >> 8) & 0xFF;
G_io_apdu_buffer[11] = (TARGET_ID >> 0) & 0xFF;
G_io_apdu_buffer[14] = (TARGET_ID >> 24) & 0xFF;
G_io_apdu_buffer[15] = (TARGET_ID >> 16) & 0xFF;
G_io_apdu_buffer[16] = (TARGET_ID >> 8) & 0xFF;
G_io_apdu_buffer[17] = (TARGET_ID >> 0) & 0xFF;

*tx += 12;
*tx += 18;
THROW(APDU_CODE_OK);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/substrate/substrate_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,7 @@ parser_error_t _toStringPercent(
uint8_t pageIdx,
uint8_t* pageCount)
{
char bufferUI[50];
char bufferUI[60];
char bufferRatio[50];

uint64_to_str(bufferRatio, sizeof(bufferRatio), v->value);
Expand Down
23 changes: 23 additions & 0 deletions fuzz/generateInitialCorpus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
import os

def extract_blobs(json_file, initial_corpus_dir):
# Load the JSON file containing the test cases
with open(json_file, 'r') as file:
test_cases = json.load(file)

# Write the 'blob' field of each test case to a separate file in the initial_corpus_dir
for i, test_case in enumerate(test_cases):
blob_content = test_case.get('blob', '') # Get the 'blob' field or default to empty string if not found
if blob_content: # Only write out if blob_content is not empty
case_path = os.path.join(initial_corpus_dir, f'blob_{i}.txt')
with open(case_path, 'w') as case_file:
case_file.write(blob_content)

# Ensure the initial_corpus_dir is created
initial_corpus_dir = os.path.join('fuzz', 'corpora', 'initial_corpus')
os.makedirs(initial_corpus_dir, exist_ok=True)

# Process both current and previous test cases
extract_blobs('tests/testcases_current.json', initial_corpus_dir)
extract_blobs('tests/testcases_previous.json', initial_corpus_dir)
6 changes: 4 additions & 2 deletions fuzz/run-fuzzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

artifact_dir = os.path.join('fuzz', 'corpora', f'{fuzzer}-artifacts')
corpus_dir = os.path.join('fuzz', 'corpora', f'{fuzzer}')
fuzz_path = os.path.join(f'build/bin/fuzz-{fuzzer}')
fuzz_path = os.path.join(f'build/fuzz-{fuzzer}')
initial_corpus_dir = os.path.join('fuzz', 'corpora', 'initial_corpus')

os.makedirs(artifact_dir, exist_ok=True)
os.makedirs(corpus_dir, exist_ok=True)
os.makedirs(initial_corpus_dir, exist_ok=True)

env = os.environ.copy()
env['ASAN_OPTIONS'] = 'halt_on_error=1:print_stacktrace=1'
Expand All @@ -34,6 +36,6 @@
f'-max_len={max_len}',
f'-mutate_depth={MUTATE_DEPTH}',
f'-artifact_prefix={artifact_dir}/',
corpus_dir]
corpus_dir, initial_corpus_dir]
print(' '.join(shlex.quote(c) for c in cmd))
subprocess.call(cmd, env=env)
Binary file modified tests_zemu/snapshots/sp-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/st-mainmenu/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 19110a8

Please sign in to comment.