From 328d996fbe7988b3b99b71fda6b1a91014c3d52e Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Wed, 26 Jun 2024 19:59:55 +0900 Subject: [PATCH] gmacros: Avoid casting functions gmacros.h casts functions to GDestroyNotify, which prevents enabling the following hardening options in applications: -fsanitize=address -fsanitize=cfi-icall (without -fsanitize-cfi-icall-generalize-pointers), and -Wcast-function-type-strict. Define another inline function that warps the original function into GDestroyNotify. Signed-off-by: Akihiko Odaki --- glib/gmacros.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/glib/gmacros.h b/glib/gmacros.h index 2d66c2f0c..3bc402849 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -1337,6 +1337,7 @@ /* these macros are private; note that gstdio.h also uses _GLIB_CLEANUP */ #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName #define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName +#define _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName) glib_autoptr_destroy_##TypeName #define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr #define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName #define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr @@ -1356,12 +1357,14 @@ { if (_ptr) (cleanup) ((ParentName *) _ptr); } \ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) \ { _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); } \ + static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName) (void *_ptr) \ + { (cleanup) ((ParentName *) _ptr); } \ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) \ - { g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \ + { g_list_free_full (*_l, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) \ - { g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \ + { g_slist_free_full (*_l, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) (GQueue **_q) \ - { if (*_q) g_queue_free_full (*_q, (GDestroyNotify) (void(*)(void)) cleanup); } \ + { if (*_q) g_queue_free_full (*_q, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \ G_GNUC_END_IGNORE_DEPRECATIONS #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \ _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))