From eef3b1f8662bf76095987eeef41308094693cf3e Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 29 Mar 2023 19:42:51 +0100 Subject: [PATCH 1/2] Check for empty closures The closure field of the callback info structure can be NULL, which means we need to check before calling functions on it. Fixes: https://rt.cpan.org/Public/Bug/Display.html?id=147409 Closes: #4 --- gperl-i11n-marshal-callback.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gperl-i11n-marshal-callback.c b/gperl-i11n-marshal-callback.c index 14ad003..d422de6 100644 --- a/gperl-i11n-marshal-callback.c +++ b/gperl-i11n-marshal-callback.c @@ -57,8 +57,11 @@ sv_to_callback (GIArgInfo * arg_info, callback_info->closure, callback_info); #if GI_CHECK_VERSION (1, 72, 0) - return g_callable_info_get_closure_native_address (callback_interface_info, - callback_info->closure); + if (callback_info->closure) + return g_callable_info_get_closure_native_address (callback_interface_info, + callback_info->closure); + else + return NULL; #else return callback_info->closure; #endif -- GitLab From f07294330f0dc03b9f851d898ef7ed02b3291b6d Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 29 Mar 2023 20:14:31 +0100 Subject: [PATCH 2/2] tests: Add empty callback Check that we're not trying to access an undefined callable. --- t/callbacks.t | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/t/callbacks.t b/t/callbacks.t index af035fd..e8d3035 100644 --- a/t/callbacks.t +++ b/t/callbacks.t @@ -5,11 +5,15 @@ BEGIN { require './t/inc/setup.pl' }; use strict; use warnings; -plan tests => 25; +plan tests => 27; my $data = 42; my $result = 23; my $callback = sub { is @_, 1; is $_[0], $data; return $result; }; +my $empty_callback = sub { return $result }; + +is (Regress::test_callback ($empty_callback), $result); +is (Regress::test_callback (undef), 0); is (Regress::test_callback_user_data ($callback, $data), $result); -- GitLab