mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 18:40:16 +01:00
libnm/tests: avoid coverity warning in test_setting_connection_secondaries_verify()
nm_strvarray_get_strv() returns the input pointer itself, if _secondaries is NULL.
It does so intentionally and correctly to create an artificial empty strv array.
Coverity doesn't like this. Try to workaround the warning:
Error: ARRAY_VS_SINGLETON (CWE-119): [#def484]
NetworkManager-1.31.90/src/libnm-core-impl/tests/test-setting.c:4544: address_of: Taking address with "&_secondaries" yields a singleton pointer.
NetworkManager-1.31.90/src/libnm-core-impl/tests/test-setting.c:4544: identity_transfer: Passing "&_secondaries" as argument 1 to function "nm_strvarray_get_strv", which returns that argument.
NetworkManager-1.31.90/src/libnm-core-impl/tests/test-setting.c:4544: callee_ptr_arith: Passing "_Generic (nm_strvarray_get_strv(&_secondaries, NULL), char const * const * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char const ** : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char * const * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char ** : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void const * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void * : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char const * const * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char const ** const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char * const * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), char ** const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void const * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL), void * const : (char const * const *)nm_strvarray_get_strv(&_secondaries, NULL))" to function "_nm_utils_strv_cmp_n" which uses it as an array. This might corrupt or misinterpret adjacent memory locations.
# 4542| G_STMT_END
# 4543|
# 4544|-> _assert_secondaries(s_con, (const char *const *) arr->pdata);
# 4545|
# 4546| /* reimplement the normalization that we expect to happen and
(cherry picked from commit 14ec96f262)
This commit is contained in:
parent
91f5c5e763
commit
6df0c8e9bb
1 changed files with 38 additions and 36 deletions
|
|
@ -4503,42 +4503,44 @@ test_setting_connection_secondaries_verify(void)
|
|||
|
||||
g_object_set(s_con, NM_SETTING_CONNECTION_SECONDARIES, arr->pdata, NULL);
|
||||
|
||||
#define _assert_secondaries(s_con, expected) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
NMSettingConnection *const _s_con = (s_con); \
|
||||
const char *const * _expected = (expected); \
|
||||
GArray * _secondaries; \
|
||||
const guint _expected_len = NM_PTRARRAY_LEN(_expected); \
|
||||
gs_strfreev char ** _sec_strv = NULL; \
|
||||
guint _i; \
|
||||
\
|
||||
g_assert(_expected); \
|
||||
\
|
||||
if (nmtst_get_rand_bool()) { \
|
||||
_secondaries = _nm_setting_connection_get_secondaries(_s_con); \
|
||||
g_assert_cmpint(_expected_len, ==, nm_g_array_len(_secondaries)); \
|
||||
g_assert((_expected_len == 0) == (!_secondaries)); \
|
||||
g_assert(nm_utils_strv_equal(_expected, nm_strvarray_get_strv(&_secondaries, NULL))); \
|
||||
} \
|
||||
\
|
||||
if (nmtst_get_rand_bool()) { \
|
||||
g_object_get(_s_con, NM_SETTING_CONNECTION_SECONDARIES, &_sec_strv, NULL); \
|
||||
g_assert_cmpint(_expected_len, ==, NM_PTRARRAY_LEN(_sec_strv)); \
|
||||
g_assert((_expected_len == 0) == (!_sec_strv)); \
|
||||
g_assert(nm_utils_strv_equal(_expected, _sec_strv ?: NM_STRV_EMPTY())); \
|
||||
} \
|
||||
\
|
||||
g_assert_cmpint(nm_setting_connection_get_num_secondaries(_s_con), ==, _expected_len); \
|
||||
if (nmtst_get_rand_bool()) { \
|
||||
for (_i = 0; _i < _expected_len; _i++) { \
|
||||
g_assert_cmpstr(nm_setting_connection_get_secondary(_s_con, _i), \
|
||||
==, \
|
||||
_expected[_i]); \
|
||||
} \
|
||||
g_assert_null(nm_setting_connection_get_secondary(_s_con, _expected_len)); \
|
||||
} \
|
||||
} \
|
||||
#define _assert_secondaries(s_con, expected) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
NMSettingConnection *const _s_con = (s_con); \
|
||||
const char *const * _expected = (expected); \
|
||||
GArray * _secondaries; \
|
||||
const guint _expected_len = NM_PTRARRAY_LEN(_expected); \
|
||||
gs_strfreev char ** _sec_strv = NULL; \
|
||||
guint _i; \
|
||||
\
|
||||
g_assert(_expected); \
|
||||
\
|
||||
if (nmtst_get_rand_bool()) { \
|
||||
_secondaries = _nm_setting_connection_get_secondaries(_s_con); \
|
||||
g_assert_cmpint(_expected_len, ==, nm_g_array_len(_secondaries)); \
|
||||
g_assert((_expected_len == 0) == (!_secondaries)); \
|
||||
g_assert(nm_utils_strv_equal(_expected, \
|
||||
_secondaries ? nm_strvarray_get_strv(&_secondaries, NULL) \
|
||||
: NM_PTRARRAY_EMPTY(const char *))); \
|
||||
} \
|
||||
\
|
||||
if (nmtst_get_rand_bool()) { \
|
||||
g_object_get(_s_con, NM_SETTING_CONNECTION_SECONDARIES, &_sec_strv, NULL); \
|
||||
g_assert_cmpint(_expected_len, ==, NM_PTRARRAY_LEN(_sec_strv)); \
|
||||
g_assert((_expected_len == 0) == (!_sec_strv)); \
|
||||
g_assert(nm_utils_strv_equal(_expected, _sec_strv ?: NM_STRV_EMPTY())); \
|
||||
} \
|
||||
\
|
||||
g_assert_cmpint(nm_setting_connection_get_num_secondaries(_s_con), ==, _expected_len); \
|
||||
if (nmtst_get_rand_bool()) { \
|
||||
for (_i = 0; _i < _expected_len; _i++) { \
|
||||
g_assert_cmpstr(nm_setting_connection_get_secondary(_s_con, _i), \
|
||||
==, \
|
||||
_expected[_i]); \
|
||||
} \
|
||||
g_assert_null(nm_setting_connection_get_secondary(_s_con, _expected_len)); \
|
||||
} \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
_assert_secondaries(s_con, (const char *const *) arr->pdata);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue