common/json_parse: json_to_bitcoin_amount fails to detect overflow and accepts negative/empty inputs
维护者通常 1 天内回复
评估
调研方向
错误位于 common/json_parse.c 中的 json_to_bitcoin_amount(),其溢出检查将同一个已回绕的表达式与自身比较,并且数字解析接受前导 '-' 和空的记号。请先阅读该函数和 strtoul 调用,然后找到现有的 json_parse 测试,并将报告的三个输入添加为测试用例。当三个输入都返回 false,且有效金额仍能正确解析时,即为完成。
由索引模型根据 Issue 内容生成。
描述
Issue and Steps to Reproduce
json_to_bitcoin_amount() in common/json_parse.c has multiple parsing and overflow validation flaws:
-
Tautological overflow check:
*satoshi = btc * (uint64_t)100000000 + sat; if (*satoshi != btc * (uint64_t)100000000 + sat) return false;Both sides of
*satoshi != btc * (uint64_t)100000000 + satevaluate the exact sameuint64_twrapped value after an overflow. Whenbtcis large (e.g.184467440738),btc * 100000000overflowsuint64_tand wraps around, but the check evaluateswrapped_val != wrapped_val(which isfalse), returningtruewith a corrupted satoshi value. -
Negative numbers & signs accepted:
strtoulaccepts leading'-'and converts negative values (such as"-1.00000000"or"-0.00000001") into large unsigned values (e.g.ULONG_MAX), wrapping around during multiplication and returningtrue. -
Empty tokens:
An empty token (tok->start == tok->end) is parsed as0satoshis and returnstrueinstead of returningfalse.
Steps to reproduce
Call json_to_bitcoin_amount() with:
"184467440738.00000000": returnstruewith wrapped amount90448385instead offalse."-1.00000000": returnstruewith corrupted amount instead offalse."": returnstruewith0satoshis instead offalse.
getinfo output
N/A (C unit parsing logic in common/json_parse.c)
- 主要语言
- C
- 星标
- 3.1k
- 派生
- 1k
- 平均合并
- 4 天 4 小时
- 30 天内合并 PR
- 27
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ElementsProject/lightning 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
ElementsProject/lightning#9634 ·
维护者通常 1 天内回复
-
plugins/recover: missing comma in nodes_for_gossip concatenates two bootstrap addresses into invalid address可能已有人在做 @bhuvan-somisetty 于 4 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
ElementsProject/lightning#9630 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
ElementsProject/lightning#9616 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
ElementsProject/lightning#9593 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
ElementsProject/lightning#9322 ·
维护者通常 1 天内回复
查看 ElementsProject/lightning 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 78/100
EchoTools/nevr-runtime#698 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
FujiNetWIFI/fujinet-firmware#2079 ·
维护者通常 1 天内回复
-
bug Official Image release/25.12 Supported Device target/kirkwood
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
area/archive bug
难度 2/5 1-3 小时 新手友好度 76/100
DarkFlippers/qUnleashed#374 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 84/100
VirusTotal/yara#2255 ·