File: xs-stack-realloc.t

package info (click to toggle)
libparams-validate-perl 1.31-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,360 kB
  • sloc: perl: 2,374; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 1,027 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use strict;
use warnings;

use Test::More;

BEGIN {
    $ENV{PARAMS_VALIDATE_IMPLEMENTATION} = 'XS';
    $ENV{PV_WARN_FAILED_IMPLEMENTATION}  = 1;
}

use Params::Validate qw( validate_with );

my $alloc_size;
for my $i ( 0 .. 15 ) {
    $alloc_size = 2**$i;
    test_array_spec(undef);
}

ok( 1, 'array validation succeeded with stack realloc' );

for my $i ( 0 .. 15 ) {
    $alloc_size = 2**$i;
    test_hash_spec( a => undef );
}

ok( 1, 'hash validation succeeded with stack realloc' );

done_testing();

sub grow_stack {
    my @stuff = (1) x $alloc_size;

    # "validation" always succeeds - we just need the stack to grow inside a
    # callback to trigger the bug.
    return 1;
}

sub test_array_spec {
    my @args = validate_with(
        params => \@_,
        spec   => [ { callbacks => { grow_stack => \&grow_stack } } ],
    );
}

sub test_hash_spec {
    my %args = validate_with(
        params => \@_,
        spec   => {
            a => { callbacks => { grow_stack => \&grow_stack } },
        },
    );
}