spa: fix spa_api_method_null macro NULL checks

What may be NULL in these methods is the pointer to the object
containing the spa_interface, not the interface pointer itself.

Fixes spa-acp-tool crashing with NULL deref in spa_i18n.
This commit is contained in:
Pauli Virtanen 2024-12-07 13:43:07 +02:00 committed by Wim Taymans
parent 2d30ab94c2
commit 61f9018e15
3 changed files with 14 additions and 10 deletions

View file

@ -64,7 +64,7 @@ SPA_FORMAT_ARG_FUNC(2)
SPA_API_I18N const char *
spa_i18n_text(struct spa_i18n *i18n, const char *msgid)
{
return spa_api_method_null_r(const char *, msgid, spa_i18n, &i18n->iface,
return spa_api_method_null_r(const char *, msgid, spa_i18n, i18n, &i18n->iface,
text, 0, msgid);
}
@ -73,7 +73,7 @@ spa_i18n_ntext(struct spa_i18n *i18n, const char *msgid,
const char *msgid_plural, unsigned long int n)
{
return spa_api_method_null_r(const char *, n == 1 ? msgid : msgid_plural,
spa_i18n, &i18n->iface, ntext, 0, msgid, msgid_plural, n);
spa_i18n, i18n, &i18n->iface, ntext, 0, msgid, msgid_plural, n);
}
/**

View file

@ -59,14 +59,14 @@ struct spa_plugin_loader_methods {
SPA_API_PLUGIN_LOADER struct spa_handle *
spa_plugin_loader_load(struct spa_plugin_loader *loader, const char *factory_name, const struct spa_dict *info)
{
return spa_api_method_null_r(struct spa_handle *, NULL, spa_plugin_loader, &loader->iface,
return spa_api_method_null_r(struct spa_handle *, NULL, spa_plugin_loader, loader, &loader->iface,
load, 0, factory_name, info);
}
SPA_API_PLUGIN_LOADER int
spa_plugin_loader_unload(struct spa_plugin_loader *loader, struct spa_handle *handle)
{
return spa_api_method_null_r(int, -1, spa_plugin_loader, &loader->iface,
return spa_api_method_null_r(int, -1, spa_plugin_loader, loader, &loader->iface,
unload, 0, handle);
}

View file

@ -285,20 +285,24 @@ struct spa_interface {
_res, method, version, ##__VA_ARGS__); \
_res; \
})
#define spa_api_method_null_v(type,o,method,version,...) \
#define spa_api_method_null_v(type,co,o,method,version,...) \
({ \
struct spa_interface *_i = o; \
if (SPA_LIKELY(_i != NULL)) \
struct type *_co = co; \
if (SPA_LIKELY(_co != NULL)) { \
struct spa_interface *_i = o; \
spa_interface_call(_i, struct type ##_methods, \
method, version, ##__VA_ARGS__); \
} \
})
#define spa_api_method_null_r(rtype,def,type,o,method,version,...) \
#define spa_api_method_null_r(rtype,def,type,co,o,method,version,...) \
({ \
rtype _res = def; \
struct spa_interface *_i = o; \
if (SPA_LIKELY(_i != NULL)) \
struct type *_co = co; \
if (SPA_LIKELY(_co != NULL)) { \
struct spa_interface *_i = o; \
spa_interface_call_res(_i, struct type ##_methods, \
_res, method, version, ##__VA_ARGS__); \
} \
_res; \
})
#define spa_api_method_fast_v(type,o,method,version,...) \