Skip to content

Commit

Permalink
Fix silent uint64 negative conversion status-im/nimbus-eth2#1671 stat…
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Oct 7, 2020
1 parent dff46c9 commit 9945543
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion json_rpc/jsonmarshal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ proc fromJson*(n: JsonNode, argName: string, result: var int64) =

proc fromJson*(n: JsonNode, argName: string, result: var uint64) =
n.kind.expect(JInt, argName)
result = n.getInt().uint64
let asInt = n.getInt()
# signed -> unsigned conversions are unchecked
# https://github.com/nim-lang/RFCs/issues/175
if asInt < 0:
raise newException(
ValueError, "JSON-RPC input is an unexpected negative value")
result = uint64(asInt)

proc fromJson*(n: JsonNode, argName: string, result: var ref int64) =
n.kind.expect(JInt, argName)
Expand Down

0 comments on commit 9945543

Please sign in to comment.