summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-05-06 21:24:56 +0200
committerThomas Haller <thaller@redhat.com>2021-05-11 13:56:48 +0200
commitd527d3874c31a6e11c1c59e2454da01fc4e575c3 (patch)
tree88364b1e5a579658181d9307fa67a63cc625015f
parent463db1c7a605972ec7f0b05e0a59dbc9b6208756 (diff)
downloadNetworkManager-d527d3874c31a6e11c1c59e2454da01fc4e575c3.tar.gz
glib-aux: workaround coverty warning about comparing nm_json_int_t with int64
Error: CONSTANT_EXPRESSION_RESULT (CWE-569): [#def240] NetworkManager-1.31.3/src/libnm-glib-aux/nm-json-aux.h:260: result_independent_of_operands: "v < -9223372036854775808LL /* (gint64)(-9223372036854775807L - 1L) */" is always false regardless of the values of its operands. This occurs as the logical first operand of "||". # 258| # 259| v = vt->nm_json_integer_value(elem); # 260|-> if (v < G_MININT64 || v > G_MAXINT64) # 261| return -ERANGE; # 262| Error: CONSTANT_EXPRESSION_RESULT (CWE-569): [#def241] NetworkManager-1.31.3/src/libnm-glib-aux/nm-json-aux.h:279: result_independent_of_operands: "v > 18446744073709551615UL" is always false regardless of the values of its operands. This occurs as the logical second operand of "||". # 277| # 278| v = vt->nm_json_integer_value(elem); # 279|-> if (v < 0 || v > G_MAXUINT64) # 280| return -ERANGE; # 281|
-rw-r--r--src/libnm-glib-aux/nm-json-aux.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/libnm-glib-aux/nm-json-aux.h b/src/libnm-glib-aux/nm-json-aux.h
index 1a4b539524..936e914641 100644
--- a/src/libnm-glib-aux/nm-json-aux.h
+++ b/src/libnm-glib-aux/nm-json-aux.h
@@ -256,9 +256,15 @@ nm_jansson_json_as_int64(const NMJsonVt *vt, const nm_json_t *elem, gint64 *out_
if (!nm_json_is_integer(elem))
return -EINVAL;
+ /* assert that this integer is signed. */
+ G_STATIC_ASSERT_EXPR(((nm_json_int_t) -1) < 0);
+
v = vt->nm_json_integer_value(elem);
- if (v < G_MININT64 || v > G_MAXINT64)
- return -ERANGE;
+
+ if (sizeof(v) > sizeof(gint64)) {
+ if (v < G_MININT64 || v > G_MAXINT64)
+ return -ERANGE;
+ }
NM_SET_OUT(out_val, v);
return 1;
@@ -275,10 +281,18 @@ nm_jansson_json_as_uint64(const NMJsonVt *vt, const nm_json_t *elem, guint64 *ou
if (!nm_json_is_integer(elem))
return -EINVAL;
+ /* assert that this integer is signed. */
+ G_STATIC_ASSERT_EXPR(((nm_json_int_t) -1) < 0);
+
v = vt->nm_json_integer_value(elem);
- if (v < 0 || v > G_MAXUINT64)
+ if (v < 0)
return -ERANGE;
+ if (sizeof(v) > sizeof(gint64)) {
+ if (v > G_MAXUINT64)
+ return -ERANGE;
+ }
+
NM_SET_OUT(out_val, v);
return 1;
}