From: Christopher Faulet Date: Thu, 6 Feb 2025 16:13:50 +0000 (+0100) Subject: BUG/MINOR: stats-json: Define JSON_INT_MAX as a signed integer X-Git-Tag: v3.0.9~37 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=2fe2b23ab82b0b19f83bfe7a1b61a1ae6ea856ee;p=haproxy-3.0.git BUG/MINOR: stats-json: Define JSON_INT_MAX as a signed integer A JSON integer is defined in the range [-(2**53)+1, (2**53)-1]. Macro are used to define the minimum and the maximum value, The minimum one is defined using the maximum one. So JSON_INT_MAX must be defined as a signed integer value to avoid wrong cast of JSON_INT_MIN. It was reported by Coverity in #2841: CID 1587769. This patch could be backported to all stable versions. (cherry picked from commit d48b5add889db1bf2f0fae4721abb46413303d33) Signed-off-by: Willy Tarreau (cherry picked from commit d0c16f3353c5e673abb6967a714f1ca22797dbff) Signed-off-by: Amaury Denoyelle --- diff --git a/src/stats-json.c b/src/stats-json.c index b493853..f66ac73 100644 --- a/src/stats-json.c +++ b/src/stats-json.c @@ -60,7 +60,7 @@ static int stats_emit_json_field_tags(struct buffer *out, const struct field *f) /* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per * the recommendation for interoperable integers in section 6 of RFC 7159. */ -#define JSON_INT_MAX ((1ULL << 53) - 1) +#define JSON_INT_MAX ((1LL << 53) - 1) #define JSON_INT_MIN (0 - JSON_INT_MAX) /* Emits a stats field value and its type in JSON.