obs/obs-source-factory: Fix potential null-pointer-dereference

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-11-17 14:07:54 +01:00
parent 87f83738c3
commit db85883821
1 changed files with 118 additions and 60 deletions

View File

@ -79,7 +79,9 @@ namespace obs {
virtual ~source_factory() {} virtual ~source_factory() {}
private /* Factory */: private /* Factory */:
static const char* _get_name(void* type_data) noexcept try { static const char* _get_name(void* type_data) noexcept
try {
if (type_data)
return reinterpret_cast<_factory*>(type_data)->get_name(); return reinterpret_cast<_factory*>(type_data)->get_name();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -89,7 +91,8 @@ namespace obs {
return nullptr; return nullptr;
} }
static void* _create(obs_data_t* settings, obs_source_t* source) noexcept try { static void* _create(obs_data_t* settings, obs_source_t* source) noexcept
try {
return reinterpret_cast<_factory*>(obs_source_get_type_data(source))->create(settings, source); return reinterpret_cast<_factory*>(obs_source_get_type_data(source))->create(settings, source);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -99,7 +102,9 @@ namespace obs {
return nullptr; return nullptr;
} }
static void _get_defaults2(void* type_data, obs_data_t* settings) noexcept try { static void _get_defaults2(void* type_data, obs_data_t* settings) noexcept
try {
if (type_data)
reinterpret_cast<_factory*>(type_data)->get_defaults2(settings); reinterpret_cast<_factory*>(type_data)->get_defaults2(settings);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -107,7 +112,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static obs_properties_t* _get_properties2(void* data, void* type_data) noexcept try { static obs_properties_t* _get_properties2(void* data, void* type_data) noexcept
try {
if (type_data)
return reinterpret_cast<_factory*>(type_data)->get_properties2(reinterpret_cast<_instance*>(data)); return reinterpret_cast<_factory*>(type_data)->get_properties2(reinterpret_cast<_instance*>(data));
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -118,7 +125,9 @@ namespace obs {
} }
private /* Instance */: private /* Instance */:
static void _destroy(void* data) noexcept try { static void _destroy(void* data) noexcept
try {
if (data)
delete reinterpret_cast<_instance*>(data); delete reinterpret_cast<_instance*>(data);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -126,7 +135,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static uint32_t _get_width(void* data) noexcept try { static uint32_t _get_width(void* data) noexcept
try {
if (data)
return reinterpret_cast<_instance*>(data)->get_width(); return reinterpret_cast<_instance*>(data)->get_width();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -136,7 +147,9 @@ namespace obs {
return 0; return 0;
} }
static uint32_t _get_height(void* data) noexcept try { static uint32_t _get_height(void* data) noexcept
try {
if (data)
return reinterpret_cast<_instance*>(data)->get_height(); return reinterpret_cast<_instance*>(data)->get_height();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -146,7 +159,9 @@ namespace obs {
return 0; return 0;
} }
static void _update(void* data, obs_data_t* settings) noexcept try { static void _update(void* data, obs_data_t* settings) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->update(settings); reinterpret_cast<_instance*>(data)->update(settings);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -154,7 +169,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _activate(void* data) noexcept try { static void _activate(void* data) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->activate(); reinterpret_cast<_instance*>(data)->activate();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -162,7 +179,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _deactivate(void* data) noexcept try { static void _deactivate(void* data) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->deactivate(); reinterpret_cast<_instance*>(data)->deactivate();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -170,7 +189,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _show(void* data) noexcept try { static void _show(void* data) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->show(); reinterpret_cast<_instance*>(data)->show();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -178,7 +199,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _hide(void* data) noexcept try { static void _hide(void* data) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->hide(); reinterpret_cast<_instance*>(data)->hide();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -186,7 +209,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _video_tick(void* data, float seconds) noexcept try { static void _video_tick(void* data, float seconds) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->video_tick(seconds); reinterpret_cast<_instance*>(data)->video_tick(seconds);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -194,7 +219,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _video_render(void* data, gs_effect_t* effect) noexcept try { static void _video_render(void* data, gs_effect_t* effect) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->video_render(effect); reinterpret_cast<_instance*>(data)->video_render(effect);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -202,7 +229,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static struct obs_source_frame* _filter_video(void* data, struct obs_source_frame* frame) noexcept try { static struct obs_source_frame* _filter_video(void* data, struct obs_source_frame* frame) noexcept
try {
if (data)
return reinterpret_cast<_instance*>(data)->filter_video(frame); return reinterpret_cast<_instance*>(data)->filter_video(frame);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -212,7 +241,9 @@ namespace obs {
return frame; return frame;
} }
static struct obs_audio_data* _filter_audio(void* data, struct obs_audio_data* frame) noexcept try { static struct obs_audio_data* _filter_audio(void* data, struct obs_audio_data* frame) noexcept
try {
if (data)
return reinterpret_cast<_instance*>(data)->filter_audio(frame); return reinterpret_cast<_instance*>(data)->filter_audio(frame);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -222,7 +253,9 @@ namespace obs {
return frame; return frame;
} }
static void _enum_active_sources(void* data, obs_source_enum_proc_t enum_callback, void* param) noexcept try { static void _enum_active_sources(void* data, obs_source_enum_proc_t enum_callback, void* param) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->enum_active_sources(enum_callback, param); reinterpret_cast<_instance*>(data)->enum_active_sources(enum_callback, param);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -230,7 +263,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _save(void* data, obs_data_t* settings) noexcept try { static void _save(void* data, obs_data_t* settings) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->save(settings); reinterpret_cast<_instance*>(data)->save(settings);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -238,7 +273,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _load(void* data, obs_data_t* settings) noexcept try { static void _load(void* data, obs_data_t* settings) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->load(settings); reinterpret_cast<_instance*>(data)->load(settings);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -247,7 +284,9 @@ namespace obs {
} }
static void _mouse_click(void* data, const struct obs_mouse_event* event, int32_t type, bool mouse_up, static void _mouse_click(void* data, const struct obs_mouse_event* event, int32_t type, bool mouse_up,
uint32_t click_count) noexcept try { uint32_t click_count) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->mouse_click(event, type, mouse_up, click_count); reinterpret_cast<_instance*>(data)->mouse_click(event, type, mouse_up, click_count);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -255,7 +294,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _mouse_move(void* data, const struct obs_mouse_event* event, bool mouse_leave) noexcept try { static void _mouse_move(void* data, const struct obs_mouse_event* event, bool mouse_leave) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->mouse_move(event, mouse_leave); reinterpret_cast<_instance*>(data)->mouse_move(event, mouse_leave);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -263,8 +304,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _mouse_wheel(void* data, const struct obs_mouse_event* event, int x_delta, static void _mouse_wheel(void* data, const struct obs_mouse_event* event, int x_delta, int y_delta) noexcept
int y_delta) noexcept try { try {
if (data)
reinterpret_cast<_instance*>(data)->mouse_wheel(event, x_delta, y_delta); reinterpret_cast<_instance*>(data)->mouse_wheel(event, x_delta, y_delta);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -272,7 +314,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _focus(void* data, bool focus) noexcept try { static void _focus(void* data, bool focus) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->focus(focus); reinterpret_cast<_instance*>(data)->focus(focus);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -280,15 +324,19 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _key_click(void* data, const struct obs_key_event* event, bool key_up) noexcept try { static void _key_click(void* data, const struct obs_key_event* event, bool key_up) noexcept
try {
reinterpret_cast<_instance*>(data)->key_click(event, key_up); reinterpret_cast<_instance*>(data)->key_click(event, key_up);
if (data)
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
} catch (...) { } catch (...) {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _filter_remove(void* data, obs_source_t* source) noexcept try { static void _filter_remove(void* data, obs_source_t* source) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->filter_remove(source); reinterpret_cast<_instance*>(data)->filter_remove(source);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -297,7 +345,9 @@ namespace obs {
} }
static bool _audio_render(void* data, uint64_t* ts_out, struct obs_source_audio_mix* audio_output, static bool _audio_render(void* data, uint64_t* ts_out, struct obs_source_audio_mix* audio_output,
uint32_t mixers, size_t channels, size_t sample_rate) noexcept try { uint32_t mixers, size_t channels, size_t sample_rate) noexcept
try {
if (data)
return reinterpret_cast<_instance*>(data)->audio_render(ts_out, audio_output, mixers, channels, return reinterpret_cast<_instance*>(data)->audio_render(ts_out, audio_output, mixers, channels,
sample_rate); sample_rate);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
@ -308,7 +358,9 @@ namespace obs {
return false; return false;
} }
static void _enum_all_sources(void* data, obs_source_enum_proc_t enum_callback, void* param) noexcept try { static void _enum_all_sources(void* data, obs_source_enum_proc_t enum_callback, void* param) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->enum_all_sources(enum_callback, param); reinterpret_cast<_instance*>(data)->enum_all_sources(enum_callback, param);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -316,7 +368,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _transition_start(void* data) noexcept try { static void _transition_start(void* data) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->transition_start(); reinterpret_cast<_instance*>(data)->transition_start();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -324,7 +378,9 @@ namespace obs {
P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); P_LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
static void _transition_stop(void* data) noexcept try { static void _transition_stop(void* data) noexcept
try {
if (data)
reinterpret_cast<_instance*>(data)->transition_stop(); reinterpret_cast<_instance*>(data)->transition_stop();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());
@ -333,7 +389,9 @@ namespace obs {
} }
static bool _audio_mix(void* data, uint64_t* ts_out, struct audio_output_data* audio_output, size_t channels, static bool _audio_mix(void* data, uint64_t* ts_out, struct audio_output_data* audio_output, size_t channels,
size_t sample_rate) noexcept try { size_t sample_rate) noexcept
try {
if (data)
return reinterpret_cast<_instance*>(data)->audio_mix(ts_out, audio_output, channels, sample_rate); return reinterpret_cast<_instance*>(data)->audio_mix(ts_out, audio_output, channels, sample_rate);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); P_LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what());