From: Lennart Poettering Date: Mon, 25 May 2020 16:21:08 +0000 (+0200) Subject: json: turn off ubsan for json_variant_has_type() X-Git-Tag: v246-rc1~292^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e2fa6e2236ec81c86612f75103f36ba699193c8;p=thirdparty%2Fsystemd.git json: turn off ubsan for json_variant_has_type() Fixes: #15907 --- diff --git a/src/basic/macro.h b/src/basic/macro.h index 73b391c27c8..b48d3990972 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -84,6 +84,14 @@ #define _variable_no_sanitize_address_ #endif +/* Apparently there's no has_feature() call defined to check for ubsan, hence let's define this + * unconditionally on llvm */ +#if defined(__clang__) +#define _function_no_sanitize_float_cast_overflow_ __attribute__((no_sanitize("float-cast-overflow"))) +#else +#define _function_no_sanitize_float_cast_overflow_ +#endif + /* Temporarily disable some warnings */ #define DISABLE_WARNING_FORMAT_NONLITERAL \ _Pragma("GCC diagnostic push"); \ diff --git a/src/shared/json.c b/src/shared/json.c index a3ad5b996a7..27a3a518fef 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -1093,9 +1093,12 @@ JsonVariantType json_variant_type(JsonVariant *v) { return v->type; } -bool json_variant_has_type(JsonVariant *v, JsonVariantType type) { +_function_no_sanitize_float_cast_overflow_ bool json_variant_has_type(JsonVariant *v, JsonVariantType type) { JsonVariantType rt; + /* Note: we turn off ubsan float cast overflo detection for this function, since it would complain + * about our float casts but we do them explicitly to detect conversion errors. */ + v = json_variant_dereference(v); if (!v) return false;