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 テストを見つけて、報告された3つの入力をテストケースとして追加してください。3つすべてが 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
- 平均マージ
- 3日 18時間
- マージ済み PR(30日)
- 33
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ElementsProject/lightning のほかの issue
-
難易度 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 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ElementsProject/lightning#9206 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ElementsProject/lightning#9187 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
ElementsProject/lightning の issue をすべて見る
似ている issue
-
[BUG] Small issues on iMXRT found by Claude対応中かも @Sarthak-Pandey が今日担当しました。 オープンArch: arm Area: Networking OS: Linux Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
area: docs eco: cpp good first issue help wanted lane: free-agent roadmap size: XS type: docs
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
arminazimi/evergreen#475 ·
メンテナーはふだん 1 日以内に返信
-
[Issue]: hipsparselt.h C API as shipped now requires C23 -- ONLY because of missing include or guardオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
ROCm/rocm-libraries#13736 ·
メンテナーはふだん 2 日以内に返信
-
libc
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
llvm/llvm-project#232380 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
level/task module/auth/enrollment platform/linux reporter/qa type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信