tor, fuzz: reuse constants instead of duplicating
What changed, and why it matters
This is a minor code cleanup change. It moves two Tor status code numbers (250 for OK, 510 for unrecognized command) from one file to a shared header so both the main program and a test fuzzer use the same named constants instead of hard-coding the numbers twice. There is no security fix here and no behavior change.
No security action needed. Treat as a normal refactoring/review commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors TOR_REPLY_OK (250) and TOR_REPLY_UNRECOGNIZED (510) from static const definitions in src/torcontrol.cpp to constexpr definitions in src/torcontrol.h, then updates the fuzz test in src/test/fuzz/torcontrol.cpp to use those named constants. The values are unchanged; only duplication is removed.
Changed components
src/torcontrol.cppsrc/torcontrol.hsrc/test/fuzz/torcontrol.cppInspect captured patch +6 / −5
diff --git a/src/test/fuzz/torcontrol.cpp b/src/test/fuzz/torcontrol.cpp
index 62c2ad57..114bc524 100644
--- a/src/test/fuzz/torcontrol.cpp
+++ b/src/test/fuzz/torcontrol.cpp
@@ -49,10 +49,10 @@ FUZZ_TARGET(torcontrol, .init = initialize_torcontrol)
CallOneOf(
fuzzed_data_provider,
[&] {
- tor_control_reply.code = 250;
+ tor_control_reply.code = TOR_REPLY_OK;
},
[&] {
- tor_control_reply.code = 510;
+ tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
},
[&] {
tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index d37fc2dd..04092639 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -53,9 +53,6 @@ const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:" + ToString(DEFAULT_TOR_CONT
static const int TOR_COOKIE_SIZE = 32;
/** Size of client/server nonce for SAFECOOKIE */
static const int TOR_NONCE_SIZE = 32;
-/** Tor control reply code. Ref: https://spec.torproject.org/control-spec/replies.html */
-static const int TOR_REPLY_OK = 250;
-static const int TOR_REPLY_UNRECOGNIZED = 510;
/** For computing serverHash in SAFECOOKIE */
static const std::string TOR_SAFE_SERVERKEY = "Tor safe cookie authentication server-to-controller hash";
/** For computing clientHash in SAFECOOKIE */
diff --git a/src/torcontrol.h b/src/torcontrol.h
index e64f9d38..f331e76a 100644
--- a/src/torcontrol.h
+++ b/src/torcontrol.h
@@ -24,6 +24,10 @@ constexpr int DEFAULT_TOR_CONTROL_PORT = 9051;
extern const std::string DEFAULT_TOR_CONTROL;
static const bool DEFAULT_LISTEN_ONION = true;
+/** Tor control reply code. Ref: https://spec.torproject.org/control-spec/replies.html */
+constexpr int TOR_REPLY_OK{250};
+constexpr int TOR_REPLY_UNRECOGNIZED{510};
+
void StartTorControl(CService onion_service_target);
void InterruptTorControl();
void StopTorControl();
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.