btcjson: accept null in StringOrArray.UnmarshalJSON
What changed, and why it matters
This commit fixes a harmless JSON decoding bug. When a Bitcoin RPC server returned a null value for the 'warnings' field, the client couldn't understand it and threw an error. The fix lets null decode to an empty list, restoring normal operation. There is no security attack here.
No security action required; treat as a normal bug fix. If desired, ensure integration tests covering getblockchaininfo pass after the change.
Security signals we found
No security-relevant signals present
Fix is a deserialization compatibility correction, not a vulnerability patch
No input validation, authentication, cryptography, or resource-control changes
Evidence from the diff
The patch adds a nil case to btcjson.StringOrArray.UnmarshalJSON so that JSON null is decoded as a nil []string slice. Previously, UnmarshalJSON handled strings and arrays but not null, causing deserialization to fail for responses where the server emitted null for an empty warnings field (e.g., getblockchaininfo). The change is a round-trip correctness fix and includes regression tests for null and omitted warnings fields.
Changed components
btcjson/chainsvrresults.gobtcjson/chainsvrresults_test.gorpcclient getblockchaininfo response decodingInspect captured patch +13 / −0
diff --git a/btcjson/chainsvrresults.go b/btcjson/chainsvrresults.go
index 3ee2b8b..5cd1e90 100644
--- a/btcjson/chainsvrresults.go
+++ b/btcjson/chainsvrresults.go
@@ -385,6 +385,9 @@ func (h *StringOrArray) UnmarshalJSON(data []byte) error {
}
switch v := unmarshalled.(type) {
+ case nil:
+ *h = nil
+
case string:
*h = []string{v}
diff --git a/btcjson/chainsvrresults_test.go b/btcjson/chainsvrresults_test.go
index fb681a9..f37adb4 100644
--- a/btcjson/chainsvrresults_test.go
+++ b/btcjson/chainsvrresults_test.go
@@ -350,6 +350,16 @@ func TestGetBlockChainInfoWarnings(t *testing.T) {
result: `{"warnings": []}`,
expected: btcjson.StringOrArray{},
},
+ {
+ name: "blockchain info with null warnings",
+ result: `{"warnings": null}`,
+ expected: nil,
+ },
+ {
+ name: "blockchain info with warnings field omitted",
+ result: `{}`,
+ expected: nil,
+ },
}
for _, test := range tests {
Why this scored 21/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.