From: Arran Cudbard-Bell Date: Tue, 3 Sep 2024 00:55:49 +0000 (-0600) Subject: Start the very long process of placating ubsan X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30b76bccf49180b4e7e567e8fdea40f4bdf97e16;p=thirdparty%2Ffreeradius-server.git Start the very long process of placating ubsan --- diff --git a/src/include/build.h b/src/include/build.h index 7d079e1d29..b4206e5898 100644 --- a/src/include/build.h +++ b/src/include/build.h @@ -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 */ diff --git a/src/lib/server/connection.c b/src/lib/server/connection.c index 2b9c5e8c35..0f8d2e752d 100644 --- a/src/lib/server/connection.c +++ b/src/lib/server/connection.c @@ -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) { /* diff --git a/src/lib/server/connection.h b/src/lib/server/connection.h index 3b034a0e07..524f5d1ca4 100644 --- a/src/lib/server/connection.h +++ b/src/lib/server/connection.h @@ -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) * @{ diff --git a/src/lib/util/dcursor.h b/src/lib/util/dcursor.h index 961eae09c2..97e8e2cbdc 100644 --- a/src/lib/util/dcursor.h +++ b/src/lib/util/dcursor.h @@ -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;