Skip to content

Commit 4e0a1df

Browse files
committed
fixes
1 parent e60d429 commit 4e0a1df

7 files changed

Lines changed: 25 additions & 20 deletions

File tree

fuzzing/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ FUZZ_DIR = fuzz_local
1010
# === PYTHON FORMATTING CONFIGURATION ===
1111
BLACK_LINE_LENGTH := 120
1212
FUZZING_DIR := .
13+
PYTHON ?= python3
1314

1415
# Default target
1516
.PHONY: help
@@ -69,7 +70,7 @@ fuzz: build_fuzz
6970
@echo "🚀 Starting fuzzing session..."
7071
@echo " Duration: $(FUZZ_TIME) seconds"
7172
@echo " Jobs: $(FUZZ_JOBS)"
72-
@python3 $(FUZZ_DIR)/run_local_fuzz.py \
73+
@$(PYTHON) $(FUZZ_DIR)/run_local_fuzz.py \
7374
--max-seconds $(FUZZ_TIME) \
7475
--jobs $(FUZZ_JOBS)
7576
@echo "🏁 Fuzzing session completed"
@@ -78,7 +79,7 @@ fuzz: build_fuzz
7879
.PHONY: fuzz_crash
7980
fuzz_crash: build_fuzz
8081
@echo "🔍 Analyzing fuzzing crashes..."
81-
@python3 $(FUZZ_DIR)/analyze_local_crashes.py
82+
@$(PYTHON) $(FUZZ_DIR)/analyze_local_crashes.py
8283

8384
# Clean fuzzing artifacts
8485
.PHONY: fuzz_clean

fuzzing/fuzz_local/analyze_local_crashes.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@ def main():
1717
# Change to fuzz directory for execution
1818
os.chdir(script_dir)
1919

20+
analyzer_script = os.path.join(fuzzing_dir, "analyze_crashes.py")
21+
if not os.path.exists(analyzer_script):
22+
print(f"Error: Analyzer script not found at {analyzer_script}")
23+
return 1
24+
2025
# Run the common crash analyzer
2126
cmd = [
2227
sys.executable,
23-
os.path.join(fuzzing_dir, "analyze_crashes.py"),
28+
analyzer_script,
2429
"--fuzz-dir",
2530
script_dir,
2631
]
2732

28-
print(f"🔍 Analyzing ledger-zxlib crashes...")
33+
print("🔍 Analyzing ledger-zxlib crashes...")
2934
print(f"Working directory: {script_dir}")
3035

31-
return subprocess.call(cmd)
36+
try:
37+
return subprocess.call(cmd)
38+
except (OSError, subprocess.SubprocessError) as e:
39+
print(f"Error executing analyzer: {e}")
40+
return 1
3241

3342

3443
if __name__ == "__main__":

fuzzing/fuzz_local/base58_fuzzer.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
1818
size_t decode_outlen = sizeof(decode_output);
1919

2020
// Create null-terminated string for decode test
21-
char *decode_input = new char[size + 1];
22-
memcpy(decode_input, data, size);
21+
std::vector<char> decode_input(size + 1);
22+
memcpy(decode_input.data(), data, size);
2323
decode_input[size] = '\0';
2424

25-
const int decode_result = decode_base58(decode_input, size, decode_output, &decode_outlen);
25+
const int decode_result = decode_base58(decode_input.data(), size, decode_output, &decode_outlen);
2626
(void)decode_result;
2727

28-
delete[] decode_input;
29-
3028
// Test encode_base58
3129
unsigned char encode_output[512];
3230
size_t encode_outlen = sizeof(encode_output);

fuzzing/fuzz_local/bech32_fuzzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
3535
char hrp[17] = {0};
3636
for (int i = 0; i < hrp_len && i < 16; i++) {
3737
// Use printable ASCII characters for HRP (a-z)
38-
hrp[i] = static_cast<char>('a' + (data[0] + i) % 26);
38+
hrp[i] = static_cast<char>('a' + (data[1] + i) % 26);
3939
}
4040
hrp[hrp_len] = '\0';
4141

fuzzing/fuzz_local/fuzz_config.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
FUZZER_JOBS = 4
88

99

10-
class FuzzConfig:
11-
"""Configuration for a single fuzzer target"""
12-
13-
def __init__(self, name: str, max_len: int = 17000):
14-
self.name = name
15-
self.max_len = max_len
10+
import sys
11+
import os
12+
# Add parent directory to path to import FuzzConfig
13+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14+
from run_fuzzers import FuzzConfig
1615

1716

1817
def get_fuzzer_configs():

fuzzing/fuzz_local/run_local_fuzz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def main():
3939
str(args.jobs),
4040
]
4141

42-
print(f"🚀 Starting ledger-zxlib fuzzing...")
42+
print("🚀 Starting ledger-zxlib fuzzing...")
4343
print(f"Working directory: {script_dir}")
4444
print(f"Duration: {args.max_seconds}s, Jobs: {args.jobs}")
4545

fuzzing/fuzz_local/segwit_addr_fuzzer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include <stdint.h>
33
#include <string.h>
44

5-
#include <iostream>
6-
75
extern "C" {
86
#include "segwit_addr.h"
97
}

0 commit comments

Comments
 (0)