Skip to content

Commit 97fcda7

Browse files
committed
threads.xs: don't Copy() null pointer
If a thread is created with no parameters, e.g. use threads; threads->new(sub {})->join; Then it tries to Copy() zero parameters to AvARRAY(params), which is null. Since v5.27.3-31-gf14cf36, this triggers an assert failure, so threaded builds have been badly broken.
1 parent f6107ca commit 97fcda7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

dist/threads/lib/threads.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use 5.008;
55
use strict;
66
use warnings;
77

8-
our $VERSION = '2.17';
8+
our $VERSION = '2.18';
99
my $XS_VERSION = $VERSION;
1010
$VERSION = eval $VERSION;
1111

dist/threads/threads.xs

+8-5
Original file line numberDiff line numberDiff line change
@@ -870,15 +870,18 @@ S_ithread_create(
870870
reallocated (and hence move) as a side effect of calls to
871871
perl_clone() and sv_dup_inc(). Hence copy the parameters
872872
somewhere under our control first, before duplicating. */
873+
if (num_params) {
873874
#if (PERL_VERSION > 8)
874-
Copy(parent_perl->Istack_base + params_start, array, num_params, SV *);
875+
Copy(parent_perl->Istack_base + params_start, array, num_params, SV *);
875876
#else
876-
Copy(parent_perl->Tstack_base + params_start, array, num_params, SV *);
877+
Copy(parent_perl->Tstack_base + params_start, array, num_params, SV *);
877878
#endif
878-
while (num_params--) {
879-
*array = sv_dup_inc(*array, clone_param);
880-
++array;
879+
while (num_params--) {
880+
*array = sv_dup_inc(*array, clone_param);
881+
++array;
882+
}
881883
}
884+
882885
#if (PERL_VERSION > 13) || (PERL_VERSION == 13 && PERL_SUBVERSION > 1)
883886
Perl_clone_params_del(clone_param);
884887
#endif

0 commit comments

Comments
 (0)