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

Potential integer overflow when using atoi() In cgi-bin/var.c

クローズ 初心者向け
#1,748 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@michaelrsweet がすでに取り組んでいます。

2026年10月23日 から。

  • #1749 @lynayur による — マージされずにクローズ
  • #1784 @JWWTSL による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c
領域
backend

調査の方向性

cgi-bin/var.c の990-992行目付近にある接尾辞解析コードから始めてください。ここでは atoi() が最後の - の後ろの数値を変換し、配列インデックスに渡しています。次に cgiSetArray() の459行目付近にある範囲チェックを確認してください。atoi() の呼び出しを strtol() に置き換え、呼び出しの前に errno をリセットし、errno が ERANGE の場合や、結果が受け入れ可能なインデックス範囲外になる場合は、int にキャストする前に値を拒否してください。この経路上に atoi() が残っておらず、範囲外の接尾辞が変換より前に拒否されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Potential problem

In cgi-bin/var.c, the numeric suffix of a form field name (the part after the last -) is converted with atoi() and used as an array index:

https://github.com/OpenPrinting/cups/blob/0420526915c79d18e643e0fd7b2ce555bb5bbd63/cgi-bin/var.c#L990-L992

If the value exceeds INT_MAX, converting it with atoi() results in undefined behavior. The subsequent atoi(ptr) - 1 may also overflow.

The practical impact appears limited because cgiSetArray() rejects indexes outside the 0..100000 range:

https://github.com/OpenPrinting/cups/blob/0420526915c79d18e643e0fd7b2ce555bb5bbd63/cgi-bin/var.c#L459

However, this check is performed only after atoi() has already processed the input, so it cannot make the conversion itself safe. Since the behavior of an out-of-range atoi() conversion is undefined, the result cannot be reliably validated by the subsequent range check and could potentially fall within the accepted range.

Possible solution

Replace atoi() with strtol(), reset errno before the conversion, and validate both errno != ERANGE and the parsed value against the expected range before converting it to int.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.
Author: Stanislav Pichugin <[email protected]>.

主要言語
C
スター
1.8k
フォーク
352
平均マージ
2日 4時間
マージ済み PR(30日)
16

環境構築

はじめの一歩

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

OpenPrinting/cups のほかの issue

OpenPrinting/cups の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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