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 |
汚染された可能性のある値が書式文字列の引数として使われています。
このクラスは書式文字列(Format String)の部分集合となります。
| クラス名 | Format String Injection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | 書式文字列インジェクション | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| クラス分類 | セキュリティ (security) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ニーモニック | IO.INJ.FMT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 対応言語 | 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/.