Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#9,617 コメント 0 件 リアクション 0 件 担当者 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 テストを見つけて、報告された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:

  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
平均マージ
3日 18時間
マージ済み PR(30日)
33

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ElementsProject/lightning のほかの issue

ElementsProject/lightning の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。