Skip to content

Commit cd1bf15

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 e6d1249 commit cd1bf15

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ EOF
967967
|
968968
|int
969969
|foo( a , char * b , OUT int c , OUTLIST int d , \
970-
| IN_OUT char * * e = 1 + 2 , long length(e) , \
970+
| IN_OUT char * * e = 1 + 2 , long length(b) , \
971971
| char* f="abc" , g = 0 , ... )
972972
EOF
973973

@@ -1607,6 +1607,13 @@ EOF
16071607
[ 1, 0, qr{\QError: length() on non-parameter 's'\E.*line 6},
16081608
"got expected error" ],
16091609
],
1610+
1611+
[
1612+
'length of int is invalid',
1613+
['int', 'foo(int a, size_t length(a))'],
1614+
[ 1, 0 , qr/length\(NAME\) not supported with typemaps other than T_PV/, 'Got expected error about length' ],
1615+
],
1616+
16101617
);
16111618
16121619
test_many($preamble, 'XS_Foo_', \@test_fns);

0 commit comments

Comments
 (0)