Skip to content

Commit e214089

Browse files
committed
Explicitly reject length(NAME) with typemaps other than T_PV
Previously, the length operator on typemaps other than T_PV would lead to that length value not being initialized, leading to segfaults and worse. Worse yet, parsexs would silently emit this erroneous code. For now it will at least give a clear error, in the future we should perhaps consider eliminating this limitation altogether.
1 parent 975d839 commit e214089

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

dist/ExtUtils-ParseXS/Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Revision history for Perl extension ExtUtils::ParseXS.
22

3+
3.59
4+
- Throw an exception when combining the length operator with a
5+
typemap other than T_PV
6+
37
3.58 Sun Jul 20 09:10:41 PM CEST 2025
48
- ExtUtils::ParseXS has been extensively restructured internally.
59
Most of these changes shouldn't be visible externally, but might

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS/Node.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,9 @@ sub lookup_input_typemap {
14071407
# as a pseudo-parameter, then override the normal typedef - which
14081408
# would emit SvPV_nolen(...) - and instead, emit SvPV(...,
14091409
# STRLEN_length_of_foo)
1410-
if ($xstype eq 'T_PV' and $self->{has_length}) {
1410+
if ($self->{has_length}) {
1411+
die "length(NAME) not supported with typemaps other than T_PV"
1412+
if $xstype ne 'T_PV';
14111413
die "default value not supported with length(NAME) supplied"
14121414
if defined $default;
14131415
return "($type)SvPV($arg, STRLEN_length_of_$var);",

dist/ExtUtils-ParseXS/t/001-basic.t

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,28 @@ EOF
951951

952952
}
953953

954+
{
955+
my $pxs = ExtUtils::ParseXS->new;
956+
my $text = Q(<<'EOF');
957+
|MODULE = Foo PACKAGE = Foo
958+
|
959+
|PROTOTYPES: DISABLE
960+
|
961+
|int
962+
|foo( int a, size_t length(a))
963+
EOF
964+
965+
tie *FH, 'Capture';
966+
ok !eval {
967+
$pxs->process_file( filename => \$text, output => \*FH);
968+
}, 'Invalid length argument';
969+
970+
my $out = tied(*FH)->content;
971+
972+
like($@, qr/length\(NAME\) not supported with typemaps other than T_PV/, 'Got expected error about length');
973+
}
974+
975+
954976
{
955977
# Basic check of a "usage: ..." string.
956978
# In particular, it should strip away type and IN/OUT class etc.
@@ -967,7 +989,7 @@ EOF
967989
|
968990
|int
969991
|foo( a , char * b , OUT int c , OUTLIST int d , \
970-
| IN_OUT char * * e = 1 + 2 , long length(e) , \
992+
| IN_OUT char * * e = 1 + 2 , long length(b) , \
971993
| char* f="abc" , g = 0 , ... )
972994
EOF
973995

0 commit comments

Comments
 (0)