Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

common/json_parse: json_to_bitcoin_amount fails to detect overflow and accepts negative/empty inputs

未关闭 适合新手
#9,617 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@bhuvan-somisetty 已经在做这个了。

开始于 2026年10月10日。

  • #9618 来自 @bhuvan-somisetty —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
c
领域
backend

调研方向

错误位于 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:

  1. 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 + sat evaluate the exact same uint64_t wrapped value after an overflow. When btc is large (e.g. 184467440738), btc * 100000000 overflows uint64_t and wraps around, but the check evaluates wrapped_val != wrapped_val (which is false), returning true with a corrupted satoshi value.

  2. Negative numbers & signs accepted:
    strtoul accepts 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 returning true.

  3. Empty tokens:
    An empty token (tok->start == tok->end) is parsed as 0 satoshis and returns true instead of returning false.

Steps to reproduce

Call json_to_bitcoin_amount() with:

  • "184467440738.00000000": returns true with wrapped amount 90448385 instead of false.
  • "-1.00000000": returns true with corrupted amount instead of false.
  • "": returns true with 0 satoshis instead of false.
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 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ElementsProject/lightning 的其他 Issue

查看 ElementsProject/lightning 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。