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


MISC.MEM.NTERM.CSTRING : NULL文字の無い文字列

要旨

Cの文字列としてバッファが使用されていますが、NULL終端文字を含んでいません。

プロパティ

クラス名 Unterminated C String
日本語クラス名 NULL文字の無い文字列
クラス分類 セキュリティ (security)
ニーモニック MISC.MEM.NTERM.CSTRING
カテゴリー
MisraC2025 MisraC2025:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
MisraC2023 MisraC2023:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
Misra2012 Misra2012:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
AUTOSARC++14 AUTOSARC++14:A27-0-2 A C-style string shall guarantee sufficient space for data and the null terminator.
MisraC++2023 MisraC++2023:0.3.2 A function call shall not violate the function's preconditions
  MisraC++2023:4.1.3 There shall be no occurrence of undefined or critical unspecified behaviour
CWE CWE:170 Improper Null Termination
TS17961 TS17961:5.30-nonnullstr Passing a non-null-terminated string to a library function
CERT-C CERT-C:POS30-C Use the readlink() function properly
  CERT-C:STR32-C Do not pass a non-null-terminated character sequence to a library function that expects a string
対応言語 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(),

Functions That Can Produce Unterminated Strings

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/.