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の文字列としてバッファが使用されていますが、NULL終端文字を含んでいません。
| クラス名 | Unterminated C String | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | NULL文字の無い文字列 | ||||||||||||||||||||||||||||||
| クラス分類 | セキュリティ (security) | ||||||||||||||||||||||||||||||
| ニーモニック | MISC.MEM.NTERM.CSTRING | ||||||||||||||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||||||||||||||
| 対応言語 | C および C++ で利用可能です。 |
||||||||||||||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Unterminated C String" |
#include <string.h>
#include <stdlib.h>
void f(void)
{
char buf[10];
char buf2[10];
const char *val = getenv("foo");
if( !val )
return;
strncpy( buf, val, sizeof(buf) - 1 );
strcpy( buf2, buf ); // Warning issued here because strncpy didn't terminate
}
CodeSonar ships with library models that allow it to a large number of functions that have undefined or undesirable behavior when passed an unterminated string. If one of these functions is called with an unterminated string in the relevant 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 Unterminated C String warnings.
The functions that CodeSonar considers to be capable of outputting unterminated strings are described below.
| Functions that can trigger warnings include... | |
|---|---|
| Apache Portable Runtime (APR) | apr_cpystrn(), apr_pmemdup() |
| gcc Builtins | __builtin___fprintf_chk(), __builtin___memcpy_chk(), __builtin___strncat_chk() |
| LDAP | ldap_search_ext() |
| libc | execl(), fprintf(), strcat() |
| libintl | dcgettext(), textdomain() |
| libpq | PQexec(), PQprepare() |
| Mac OS X | copyin() |
| ODBC | SQLExecDirectA(), SQLExecDirectUNIX(), SQLExecDirectW() |
| OpenSSL | CRYPTO_strdup() |
| Qt | fatal, qMemCopy() |
| C++ Standard Template Library (STL) | __throw_domain_error(), __throw_invalid_argument() |
| Win32 | PathResolve(), UnicodeToBytes(), wcscpy(), |
CodeSonar ships with library models that allow it to recognize a large number of functions that are capable of outputting unterminated strings. Some examples are shown in the table below.
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 treated as outputting unterminated strings in the same circumstances.
Additionally, CodeSonar may determine that directly writing non-NULL characters into a string has caused the string to be unterminated.
| Functions that can output an unterminated string include... | |
|---|---|
| Apache Portable Runtime (APR) | apr_cpystrn(), apr_pmemdup() |
| C++ operators | operator new() |
| FreeRTOS | pvPortMalloc() |
| gcc Builtins | __builtin___memcpy_chk(), __builtin___strncpy_chk() |
| libc | copylist(), memcpy(), strdup() |
| Linux Kernel | copy_from_user(), kmalloc() |
| Mac OS X | copyin(), kalloc() |
| Nucleus | DMCE_Allocate_Memory(), PMCE_Create_Partition_Pool() |
| ODBC | SQLNativeSqlA(), SQLNativeSqlUNIX(), SQLNativeSqlW() |
| OpenSSL | CRYPTO_malloc(), CRYPTO_strdup() |
| Qt | qMalloc(), qMemCopy() |
| VxWorks | memPartAlignedAlloc(), msgQCreate() |
| Win32 | GlobalAlloc(), _fsopen(), wcsncpy() |
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.