Strictly speaking, xdrproc_t is declared as following:
typedef bool_t (*xdrproc_t)(XDR *, ...);
But our rpcgen generates properly typed functions, e.g.:
bool_t xdr_virNetMessageError(XDR *xdrs, virNetMessageError *objp)
Now, these functions of ours are passed around as callbacks (via
an argument of xdrproc_t type), for instance in
virNetMessageEncodePayload(). But these two types are strictly
different. We silence the compiler by typecasting the callbacks
when passing them, but strictly speaking - calling such callback
later, when a function of xdrproc_t is expected is an undefined
behavior.
Ideally, we would fix our rpcgen to generate proper function
headers, but: a) my brain is too small to do that, and b) we
would lose compiler protection if an xdr_*() function is called
directly but argument of a wrong type is passed.
Silence UBSAN for now.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
cc_flags += [ '-fsemantic-interposition' ]
endif
+if get_option('b_sanitize') != 'none'
+ # This is needed because of xdrproc_t. It's declared as a pointer to a
+ # function with variable arguments. But for catching type related problems at
+ # compile time, our rpcgen generates functions with proper types, say:
+ #
+ # bool_t xdr_TestEnum(XDR *, TestEnum *);
+ #
+ # But passing xdr_TestEnum as a callback where xdrproc_t type is expected is
+ # undefined behavior. Yet, we want the comfort of compile time checks, so
+ # just disable the sanitizer warning for now. It's a big hammer though.
+ cc_flags += [ '-fno-sanitize=function' ]
+endif
+
supported_cc_flags = []
if get_option('warning_level') == '2'
supported_cc_flags = cc.get_supported_arguments(cc_flags)