diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2018-10-07 14:01:08 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2018-10-07 14:01:08 +0200 |
commit | 84d62285e4f82ebb52213ea4b8c880cec2eb9abd (patch) | |
tree | d791dcf0fbed5d415c4133bd9b3cd3af03f44120 | |
parent | 232952f2300340bdf26f67638e9533310c8525d1 (diff) | |
parent | 1881983859da99a4a50753367147c56db2c6d14b (diff) |
merge: branch 'bg/covscan'
Some coverity fixes.
https://github.com/NetworkManager/NetworkManager/pull/220
-rwxr-xr-x | examples/dispatcher/10-ifcfg-rh-routes.sh | 4 | ||||
-rw-r--r-- | libnm-core/nm-setting-ip-config.c | 2 | ||||
-rw-r--r-- | libnm-core/nm-setting-sriov.c | 2 | ||||
-rw-r--r-- | libnm-core/nm-setting-team.c | 4 | ||||
-rw-r--r-- | libnm-core/nm-setting.c | 4 | ||||
-rw-r--r-- | libnm-core/nm-utils.c | 22 | ||||
-rw-r--r-- | shared/nm-utils/nm-shared-utils.c | 2 | ||||
-rw-r--r-- | shared/nm-utils/nm-shared-utils.h | 29 | ||||
-rw-r--r-- | src/devices/nm-device-ethernet-utils.c | 2 |
9 files changed, 49 insertions, 22 deletions
diff --git a/examples/dispatcher/10-ifcfg-rh-routes.sh b/examples/dispatcher/10-ifcfg-rh-routes.sh index 147506e47..d72400aed 100755 --- a/examples/dispatcher/10-ifcfg-rh-routes.sh +++ b/examples/dispatcher/10-ifcfg-rh-routes.sh @@ -45,7 +45,7 @@ handle_ip_file() { } -if [ "$2" != "pre-up" -a "$2" != "down" ]; then +if [ "$2" != "pre-up" ] && [ "$2" != "down" ]; then exit 0 fi @@ -59,7 +59,7 @@ if [ -z "$profile" ]; then exit 0 fi -if ! [ -f "$dir/rule-$profile" -o -f "$dir/rule6-$profile" ]; then +if [ ! -f "$dir/rule-$profile" ] && [ ! -f "$dir/rule6-$profile" ]; then exit 0 fi diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index fa2535b8f..2b3134b66 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -1310,7 +1310,7 @@ nm_ip_route_attribute_validate (const char *name, return FALSE; } - if (spec->type == G_VARIANT_TYPE_STRING) { + if (g_variant_type_equal (spec->type, G_VARIANT_TYPE_STRING)) { const char *string = g_variant_get_string (value, NULL); gs_free char *string_free = NULL; char *sep; diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index d23277a02..39b872a22 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -433,7 +433,7 @@ nm_sriov_vf_attribute_validate (const char *name, return FALSE; } - if (spec->type == G_VARIANT_TYPE_STRING) { + if (g_variant_type_equal (spec->type, G_VARIANT_TYPE_STRING)) { const char *string; switch (spec->str_type) { diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index c1389d042..ec56682f7 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -125,9 +125,9 @@ nm_team_link_watcher_new_ethtool (int delay_up, NMTeamLinkWatcher *watcher; const char *val_fail = NULL; - if (delay_up < 0 || delay_up > G_MAXINT32) + if (delay_up < 0 || !_NM_INT_LE_MAXINT32 (delay_up)) val_fail = "delay-up"; - if (delay_down < 0 || delay_down > G_MAXINT32) + if (delay_down < 0 || !_NM_INT_LE_MAXINT32 (delay_up)) val_fail = "delay-down"; if (val_fail) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_FAILED, diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index a8f7668ae..e5e9ab965 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1422,7 +1422,7 @@ nm_setting_diff (NMSetting *a, } else { g_hash_table_iter_init (&iter, a_gendata->hash); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &val)) { - val2 = b_gendata ? g_hash_table_lookup (b_gendata->hash, key) : NULL; + val2 = g_hash_table_lookup (b_gendata->hash, key); compared_any = TRUE; if ( !val2 || !g_variant_equal (val, val2)) { @@ -1432,7 +1432,7 @@ nm_setting_diff (NMSetting *a, } g_hash_table_iter_init (&iter, b_gendata->hash); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &val)) { - val2 = a_gendata ? g_hash_table_lookup (a_gendata->hash, key) : NULL; + val2 = g_hash_table_lookup (a_gendata->hash, key); compared_any = TRUE; if ( !val2 || !g_variant_equal (val, val2)) { diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 724c1a6c2..eca16a138 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -5002,18 +5002,18 @@ const char **nm_utils_enum_get_values (GType type, int from, int to) static gboolean _nm_utils_is_json_object_no_validation (const char *str, GError **error) { - if (str) { - /* libjansson also requires only utf-8 encoding. */ - if (!g_utf8_validate (str, -1, NULL)) { - g_set_error_literal (error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("not valid utf-8")); - return FALSE; - } - while (g_ascii_isspace (str[0])) - str++; + nm_assert (str); + + /* libjansson also requires only utf-8 encoding. */ + if (!g_utf8_validate (str, -1, NULL)) { + g_set_error_literal (error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("not valid utf-8")); + return FALSE; } + while (g_ascii_isspace (str[0])) + str++; /* do some very basic validation to see if this might be a JSON object. */ if (str[0] == '{') { diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index 53da84280..2ace30984 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -1222,7 +1222,7 @@ nm_utils_buf_utf8safe_unescape (const char *str, gsize *out_len, gpointer *to_fr ch = (++str)[0]; if (ch >= '0' && ch <= '7') { v = v * 8 + (ch - '0'); - ch = (++str)[0]; + ++str; } } ch = v; diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index 968e375c4..fb37535d7 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -34,7 +34,7 @@ _NM_INT_NOT_NEGATIVE (gssize val) * * When using such an enum for accessing an array, one naturally wants to check * that the enum is not negative. However, the compiler doesn't like a plain - * comparisong "enum_val >= 0", because (if the enum is unsigned), it will warn + * comparison "enum_val >= 0", because (if the enum is unsigned), it will warn * that the expression is always true *duh*. Not even a cast to a signed * type helps to avoid the compiler warning in any case. * @@ -43,6 +43,33 @@ _NM_INT_NOT_NEGATIVE (gssize val) return val >= 0; } +/* check whether the integer value is smaller than G_MAXINT32. This macro exists + * for the sole purpose, that a plain "((int) value <= G_MAXINT32)" comparison + * may cause the compiler or coverity that this check is always TRUE. But the + * check depends on compile time and the size of C type "int". Of course, most + * of the time in is gint32 and an int value is always <= G_MAXINT32. The check + * exists to catch cases where that is not true. + * + * Together with the G_STATIC_ASSERT(), we make sure that this is always satisfied. */ +G_STATIC_ASSERT (sizeof (int) == sizeof (gint32)); +#if _NM_CC_SUPPORT_GENERIC +#define _NM_INT_LE_MAXINT32(value) \ + ({ \ + _nm_unused typeof (value) _value = (value); \ + \ + _Generic((value), \ + int: TRUE \ + ); \ + }) +#else +#define _NM_INT_LE_MAXINT32(value) ({ \ + _nm_unused typeof (value) _value = (value); \ + _nm_unused const int *_p_value = &_value; \ + \ + TRUE; \ + }) +#endif + /*****************************************************************************/ static inline char diff --git a/src/devices/nm-device-ethernet-utils.c b/src/devices/nm-device-ethernet-utils.c index 8bdb19917..b18eadfa9 100644 --- a/src/devices/nm-device-ethernet-utils.c +++ b/src/devices/nm-device-ethernet-utils.c @@ -29,7 +29,7 @@ nm_device_ethernet_utils_get_default_wired_name (GHashTable *existing_ids) int i; /* Find the next available unique connection name */ - for (i = 1; i <= G_MAXINT; i++) { + for (i = 1; i < G_MAXINT; i++) { temp = g_strdup_printf (_("Wired connection %d"), i); if ( !existing_ids || !g_hash_table_contains (existing_ids, temp)) |