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

Commit 8e882a1

Browse files
authored
Merge pull request #210 from Zondax/fixes
Fixes
2 parents 2e2f300 + a16c46d commit 8e882a1

13 files changed

Lines changed: 38 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ cmake_policy(SET CMP0025 NEW)
3636
cmake_policy(SET CMP0144 NEW)
3737

3838
set(HUNTER_STATUS_DEBUG ON)
39-
set(HUNTER_TLS_VERIFY OFF)
39+
set(HUNTER_TLS_VERIFY ON)
4040

4141
enable_testing()
4242

@@ -65,6 +65,11 @@ if(ENABLE_FUZZING)
6565
SET(ENABLE_SANITIZERS ON CACHE BOOL "Sanitizer automatically enabled" FORCE)
6666
SET(CMAKE_BUILD_TYPE Debug)
6767

68+
add_definitions(-DENABLE_COVERAGE=1)
69+
string(APPEND CMAKE_C_FLAGS " -fprofile-arcs -ftest-coverage")
70+
string(APPEND CMAKE_CXX_FLAGS " -fprofile-arcs -ftest-coverage")
71+
string(APPEND CMAKE_LINKER_FLAGS " -fprofile-arcs -ftest-coverage")
72+
6873
if (DEFINED ENV{FUZZ_LOGGING})
6974
add_definitions(-DFUZZING_LOGGING)
7075
message(FATAL_ERROR "Fuzz logging enabled")

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is the `transaction_version` field of `Runtime`
22
APPVERSION_M=26
33
# This is the `spec_version` field of `Runtime`
4-
APPVERSION_N=1002005
4+
APPVERSION_N=12005
55
# This is the patch version of this release
66
APPVERSION_P=0

app/src/parser_impl_common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "substrate_types.h"
2525
#include "substrate_dispatch.h"
2626

27+
#define SUPPORTED_SPEC_VERSION_V26 1002005
28+
2729
parser_error_t parser_init_context(parser_context_t *ctx,
2830
const uint8_t *buffer,
2931
uint16_t bufferSize) {
@@ -352,7 +354,7 @@ static parser_error_t _checkVersionsV26(parser_context_t *c) {
352354
transactionVersion += (uint32_t) p[3] << 24u;
353355

354356
if (transactionVersion != (SUPPORTED_TX_VERSION_CURRENT) ||
355-
specVersion != SUPPORTED_SPEC_VERSION) {
357+
specVersion != SUPPORTED_SPEC_VERSION_V26) {
356358
return parser_tx_version_not_supported;
357359
}
358360

app/src/substrate/substrate_types.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4545,7 +4545,7 @@ parser_error_t _toStringPercent(
45454545
uint8_t pageIdx,
45464546
uint8_t* pageCount)
45474547
{
4548-
char bufferUI[50];
4548+
char bufferUI[60];
45494549
char bufferRatio[50];
45504550

45514551
uint64_to_str(bufferRatio, sizeof(bufferRatio), v->value);

fuzz/generateInitialCorpus.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import os
3+
4+
def extract_blobs(json_file, initial_corpus_dir):
5+
# Load the JSON file containing the test cases
6+
with open(json_file, 'r') as file:
7+
test_cases = json.load(file)
8+
9+
# Write the 'blob' field of each test case to a separate file in the initial_corpus_dir
10+
for i, test_case in enumerate(test_cases):
11+
blob_content = test_case.get('blob', '') # Get the 'blob' field or default to empty string if not found
12+
if blob_content: # Only write out if blob_content is not empty
13+
case_path = os.path.join(initial_corpus_dir, f'blob_{i}.txt')
14+
with open(case_path, 'w') as case_file:
15+
case_file.write(blob_content)
16+
17+
# Ensure the initial_corpus_dir is created
18+
initial_corpus_dir = os.path.join('fuzz', 'corpora', 'initial_corpus')
19+
os.makedirs(initial_corpus_dir, exist_ok=True)
20+
21+
# Process both current and previous test cases
22+
extract_blobs('tests/testcases_current.json', initial_corpus_dir)
23+
extract_blobs('tests/testcases_previous.json', initial_corpus_dir)

fuzz/run-fuzzers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

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

2526
os.makedirs(artifact_dir, exist_ok=True)
2627
os.makedirs(corpus_dir, exist_ok=True)
28+
os.makedirs(initial_corpus_dir, exist_ok=True)
2729

2830
env = os.environ.copy()
2931
env['ASAN_OPTIONS'] = 'halt_on_error=1:print_stacktrace=1'
@@ -34,6 +36,6 @@
3436
f'-max_len={max_len}',
3537
f'-mutate_depth={MUTATE_DEPTH}',
3638
f'-artifact_prefix={artifact_dir}/',
37-
corpus_dir]
39+
corpus_dir, initial_corpus_dir]
3840
print(' '.join(shlex.quote(c) for c in cmd))
3941
subprocess.call(cmd, env=env)
-4 Bytes
Loading
-4 Bytes
Loading
-6 Bytes
Loading
-6 Bytes
Loading

0 commit comments

Comments
 (0)