summaryrefslogtreecommitdiff
path: root/ext/ffi/tests/bug77706.phpt
blob: 87ef584d51284eb5e4f3812c96926a42149c9e44 (plain)
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
53
54
55
56
57
58
59
60
--TEST--
Bug #77632 (FFI Segfaults When Called With Variadics)
--SKIPIF--
<?php
require_once('skipif.inc');
try {
	$libc = FFI::cdef("int printf(const char *format, ...);", "libc.so.6");
} catch (Throwable $_) {
	die('skip libc.so.6 not available');
}
?>
--INI--
ffi.enable=1
--FILE--
<?php
$header = '
typedef struct _IO_FILE FILE;
extern FILE *stdout;
extern FILE *stdin;
extern FILE *stderr;

typedef uint64_t time_t;
typedef uint32_t pid_t;

time_t time(time_t*);
pid_t getpid(void);
int fprintf(FILE *, const char *, ...);
';

$ffi = FFI::cdef($header, 'libc.so.6');

try {
    $ffi->time();
} catch (Throwable $e) {
    echo get_class($e) . ": " . $e->getMessage() . "\n";
}

try {
    $ffi->time(null, null);
} catch (Throwable $e) {
    echo get_class($e) . ": " . $e->getMessage() . "\n";
}

try {
    $ffi->fprintf($ffi->stdout);
} catch (Throwable $e) {
    echo get_class($e) . ": " . $e->getMessage() . "\n";
}

try {
    $ffi->fprintf($ffi->stdout, 123, "Hello %s\n", "World");
} catch (Throwable $e) {
    echo get_class($e) . ": " . $e->getMessage() . "\n";
}
?>
--EXPECT--
FFI\Exception: Incorrect number of arguments for C function 'time', expecting exactly 1 parameter
FFI\Exception: Incorrect number of arguments for C function 'time', expecting exactly 1 parameter
FFI\Exception: Incorrect number of arguments for C function 'fprintf', expecting at least 2 parameters
FFI\Exception: Passing incompatible argument 2 of C function 'fprintf', expecting 'char*', found PHP 'int'