]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Start the very long process of placating ubsan
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 3 Sep 2024 00:55:49 +0000 (18:55 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 3 Sep 2024 03:54:57 +0000 (21:54 -0600)
src/include/build.h
src/lib/server/connection.c
src/lib/server/connection.h
src/lib/util/dcursor.h

index 7d079e1d2924dceb9eaf3eae0416f738e470f928..b4206e5898c039d4eea96fb53a963fbbffee1ad8 100644 (file)
@@ -380,6 +380,18 @@ do { \
 #  define unpredictable(_x) _x
 #endif
 
+/*
+ *     GNU version check
+ */
+#ifdef __GNUC__
+#define        __GNUC_PREREQ__(x, y)                                           \
+       ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||                  \
+        (__GNUC__ > (x)))
+#else
+#define        __GNUC_PREREQ__(x, y)   0
+#endif
+
+
 /*
  *     Macros to add pragmas
  */
@@ -398,6 +410,26 @@ do { \
 #  define CC_RELEASE_HANDLE(_tag)
 #endif
 
+/*
+ *      Disable various forms of ubsan
+ */
+#if defined(__clang__) && __has_feature(undefined_behavior_sanitizer)
+#  define CC_NO_UBSAN(_sanitize)        __attribute__((no_sanitize(STRINGIFY(_sanitize))))
+#elif __GNUC_PREREQ__(4, 9) && defined(__SANITIZE_UNDEFINED__)
+#  define CC_NO_UBSAN(_sanitize)        __attribute__((no_sanitize_undefined))
+#else
+#  define CC_NO_UBSAN(_sanitize)
+#endif
+
+/*
+ *     Disable sanitizers for undefined behaviour
+ */
+#if defined(__clang__)
+#  define CC_NO_SANITIZE_UNDEFINED(_what) CC_HINT(no_sanitize(_what)))
+#else
+#  define CC_NO_SANITIZE_UNDEFINED(_what)
+#endif
+
 /*
  *     Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
  */
index 2b9c5e8c35c7c3739e6a321ebbe065c062841fe5..0f8d2e752d48f045ab594465c56bb884f52ce724 100644 (file)
@@ -353,6 +353,7 @@ do { \
 /** Call a list of watch functions associated with a state
  *
  */
+CC_NO_UBSAN(function) /* UBSAN: false positive - Public/private version of connection_t trips -fsanitize=function */
 static inline void connection_watch_call(connection_t *conn, fr_dlist_head_t *list)
 {
        /*
index 3b034a0e075b1b7419b2a5b35536044fd0e106d2..524f5d1ca431424c85351c91d0ea390f4a54e23f 100644 (file)
@@ -186,7 +186,7 @@ typedef void (*connection_close_t)(fr_event_list_t *el, void *h, void *uctx);
 typedef struct {
        connection_init_t               init;
        connection_open_t               open;
-       connection_shutdown_t   shutdown;
+       connection_shutdown_t           shutdown;
        connection_failed_t             failed;
        connection_close_t              close;
 } connection_funcs_t;
@@ -202,7 +202,7 @@ typedef struct {
  * @param[in] uctx     that was passed to connection_add_watch_*.
  */
 typedef void(*connection_watch_t)(connection_t *conn,
-                                    connection_state_t prev, connection_state_t state, void *uctx);
+                                 connection_state_t prev, connection_state_t state, void *uctx);
 
 /** @name Add watcher functions that get called before (pre) the state callback and after (post)
  * @{
index 961eae09c2876475730fd0626bcf808ceeab125f..97e8e2cbdc04e98f106f8e70211cccd07ea8a77d 100644 (file)
@@ -143,6 +143,7 @@ static inline void *dcursor_current_set(fr_dcursor_t *cursor, void *current)
  *     - The next attribute.
  *     - NULL if no more attributes.
  */
+CC_NO_UBSAN(function)  /* UBSAN: false positive - Type specific dcursor pointer trips --fasanitize=function */
 static inline void *dcursor_next(fr_dcursor_t *cursor, fr_dcursor_iter_t iter, void *current)
 {
        void *next;
@@ -540,6 +541,7 @@ static inline void fr_dcursor_merge(fr_dcursor_t *cursor, fr_dcursor_t *to_appen
  *
  * @hidecallergraph
  */
+CC_NO_UBSAN(function)  /* UBSAN: false positive - Type specific dcursor pointer trips --fasanitize=function */
 static inline void *fr_dcursor_filter_next(fr_dcursor_t *cursor, fr_dcursor_eval_t eval, void const *uctx)
 {
        void *item;
@@ -560,6 +562,7 @@ static inline void *fr_dcursor_filter_next(fr_dcursor_t *cursor, fr_dcursor_eval
  *
  * @hidecallergraph
  */
+CC_NO_UBSAN(function)  /* UBSAN: false positive - Type specific dcursor pointer trips --fasanitize=function */
 static inline void *fr_dcursor_filter_head(fr_dcursor_t *cursor, fr_dcursor_eval_t eval, void const *uctx)
 {
        void *item;
@@ -579,6 +582,7 @@ static inline void *fr_dcursor_filter_head(fr_dcursor_t *cursor, fr_dcursor_eval
  *
  * @hidecallergraph
  */
+ CC_NO_UBSAN(function)  /* UBSAN: false positive - Type specific dcursor pointer trips --fasanitize=function */
 static inline void *fr_dcursor_filter_current(fr_dcursor_t *cursor, fr_dcursor_eval_t eval, void const *uctx)
 {
         void *item;