JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++
Binaries


IO.INJ.FMT : 書式文字列インジェクション

要旨

汚染された可能性のある値が書式文字列の引数として使われています。

このクラスは書式文字列(Format String)の部分集合となります。

プロパティ

クラス名 Format String Injection
日本語クラス名 書式文字列インジェクション
クラス分類 セキュリティ (security)
ニーモニック IO.INJ.FMT
カテゴリー
MisraC2025 MisraC2025:D.4.14 The validity of values received from external sources shall be checked
MisraC2023 MisraC2023:D.4.14 The validity of values received from external sources shall be checked
Misra2012 Misra2012:D.4.14 The validity of values received from external sources shall be checked
AUTOSARC++14 AUTOSARC++14:A27-0-1 Inputs from independent components shall be validated.
MisraC++2023 MisraC++2023:0.3.2 A function call shall not violate the function's preconditions
CWE CWE:134 Use of Externally-Controlled Format String
TS17961 TS17961:5.23-usrfmt Including tainted or out-of-domain input in a format string
CERT-C CERT-C:FIO30-C Exclude user input from format strings
  CERT-C:FIO47-C Use valid format strings
  CERT-C:STR02-C Sanitize data passed to complex subsystems
DISA-6r1 DISA-6r1:V-222606 The application must validate all input.
  DISA-6r1:V-222609 The application must not be subject to input handling vulnerabilities.
  DISA-6r1:V-222612 The application must not be vulnerable to overflow attacks.
DISA-5r3 DISA-5r3:V-70265 The application must validate all input.
  DISA-5r3:V-70271 The application must not be subject to input handling vulnerabilities.
  DISA-5r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-4r3 DISA-4r3:V-70265 The application must validate all input.
  DISA-4r3:V-70271 The application must not be subject to input handling vulnerabilities.
  DISA-4r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-3r10 DISA-3r10:V-6164 The designer will ensure the application validates all input.
  DISA-3r10:V-16809 The designer will ensure the application does not contain format string vulnerabilities.
OWASP-2017 OWASP-2017:A1 Injection
OWASP-2021 OWASP-2021:A3 Injection
OWASP-2025 OWASP-2025:A05 Injection
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Format String Injection"

#include <stdio.h>

void tainted_input_as_fmt(void){
    char greeting[18] = "hello";
    char buf[12];
    printf("what is your name?\n");
    if (!fgets(buf, 12, stdin)) return;
    printf(buf);      /* 'Format String Injection' warning issued here
                       * - first argument to printf() has file taint
                       * ('Format String' warning also issued here)
                       */
}

void tainted_input_with_fmt(void){
    char greeting[18] = "hello";
    char buf[12];
    printf("what is your name?\n");
    if (!fgets(buf, 12, stdin)) return;
    printf("%s", buf);                /* ok: first argument to printf() is a string literal */
}

注釈

書式文字列の脆弱性は、様々な問題を引き起こす可能性がありますが、実際には問題とならない場合もあります。 上記の例では、標準入力から読み込まれた文字列が実際に人の名前であれば問題は発生しないでしょう。 しかし攻撃者は "%x %x %x %x" (書式文字列)を入力するかもしれません。 %x に対応した printf に与えられる引数は存在しませんが、 printf は可変長引数を受け取ることが出来るので、これは問題ではありません。 但し、プログラムは単純に %x に相当するスタックオフセットを計算し、その位置から4つの符号なし整数を出力します。 これは潜在的に、センシティブなデータが攻撃者に晒される危険性を秘めています。

最悪のケースでは書式文字列攻撃はプログラムをクラッシュさせ、悪意のあるコードを実行したり攻撃者にルート権限を与えてしまいます。

ワーニングを引き起こす関数

CodeSonar ships with library models that allow it to a large number of functions that take a format string parameter. If one of these functions is called with a tainted value in the format string parameter position, a warning will be issued.

If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering Format String Injection warnings.

Functions that can trigger warnings include...
Apache Portable Runtime (APR) apr_psprintf(), apr_pvsprintf()
gcc Builtins __builtin___fprintf_chk(), __builtin_snprintf()
libc fprintf(), syslog()
Win32 StringCchVPrintfA(), StringCchVPrintfW(), vsprintf_s()

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.