]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
json: turn off ubsan for json_variant_has_type()
authorLennart Poettering <lennart@poettering.net>
Mon, 25 May 2020 16:21:08 +0000 (18:21 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 26 May 2020 07:01:26 +0000 (09:01 +0200)
Fixes: #15907
src/basic/macro.h
src/shared/json.c

index 73b391c27c8a9d9711bca15daacaf2abff0161e2..b48d39909723737ac8c64e8b3283583d20166268 100644 (file)
 #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");                                 \
index a3ad5b996a7ab6de1bd169224152ac70055ae9da..27a3a518fef4270a754ef909369202e7f0cab095 100644 (file)
@@ -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;