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 Injection)の上位集合となります。
| クラス名 | Format String | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | 書式文字列 | ||||||||||||||||||||||||
| クラス分類 | セキュリティ (security) | ||||||||||||||||||||||||
| ニーモニック | MISC.FMT | ||||||||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||||||||
| 対応言語 | C および C++ で利用可能です。 |
||||||||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Format String" |
#include <stdio.h>
#include <string.h>
void param_as_fmt(char *instr){
char buf[12];
if (strlen(instr) < 11) return;
strncpy(buf, instr, 11);
memset(buf, '\0', 11);
printf(buf); /* 'Format String' warning issued here
* - first argument to printf() is a non-const string
*/
}
void param_with_fmt(char *instr){
char buf[12];
if (strlen(instr) < 11) return;
strncpy(buf, instr, 11);
memset(buf, '\0', 11);
printf("%s", buf); /* ok: first argument to printf() is a string literal */
}
書式文字列の脆弱性は、様々な問題を引き起こす可能性がありますが、実際には問題とならない場合もあります。 上記の例では、標準入力から読み込まれた文字列が実際に人の名前であれば問題は発生しないでしょう。 しかし攻撃者は "%x %x %x %x" (書式文字列)を入力するかもしれません。 %x に対応した printf に与えられる引数は存在しませんが、 printf は可変長引数を受け取ることが出来るので、これは問題ではありません。 但し、プログラムは単純に %x に相当するスタックオフセットを計算し、その位置から4つの符号なし整数を出力します。 これは潜在的に、センシティブなデータが攻撃者に晒される危険性を秘めています。
最悪のケースでは書式文字列攻撃はプログラムをクラッシュさせ、悪意のあるコードを実行したり攻撃者にルート権限を与えてしまいます。
全ての関数に対して期待された特定の引数位置に書式文字列があるか否かをチェックします。
この解析の感度は FORMAT_STRING_CHECKER_RATIO および FORMAT_STRING_CHECKER_CONFIDENCE
パラメータにより設定可能です。
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.