xref: /PHP-7.4/ext/ffi/tests/bug77706.phpt (revision a1868d22)
1--TEST--
2Bug #77632 (FFI Segfaults When Called With Variadics)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6try {
7	$libc = FFI::cdef("int printf(const char *format, ...);", "libc.so.6");
8} catch (Throwable $_) {
9	die('skip libc.so.6 not available');
10}
11?>
12--INI--
13ffi.enable=1
14--FILE--
15<?php
16$header = '
17typedef struct _IO_FILE FILE;
18extern FILE *stdout;
19extern FILE *stdin;
20extern FILE *stderr;
21
22typedef uint64_t time_t;
23typedef uint32_t pid_t;
24
25time_t time(time_t*);
26pid_t getpid(void);
27int fprintf(FILE *, const char *, ...);
28';
29
30$ffi = FFI::cdef($header, 'libc.so.6');
31
32try {
33	$ffi->time();
34} catch (Throwable $e) {
35	echo get_class($e) . ": " . $e->getMessage() . "\n";
36}
37
38try {
39	$ffi->time(null, null);
40} catch (Throwable $e) {
41	echo get_class($e) . ": " . $e->getMessage() . "\n";
42}
43
44try {
45	$ffi->fprintf($ffi->stdout);
46} catch (Throwable $e) {
47	echo get_class($e) . ": " . $e->getMessage() . "\n";
48}
49
50try {
51	$ffi->fprintf($ffi->stdout, 123, "Hello %s\n", "World");
52} catch (Throwable $e) {
53	echo get_class($e) . ": " . $e->getMessage() . "\n";
54}
55?>
56--EXPECT--
57FFI\Exception: Incorrect number of arguments for C function 'time', expecting exactly 1 parameter
58FFI\Exception: Incorrect number of arguments for C function 'time', expecting exactly 1 parameter
59FFI\Exception: Incorrect number of arguments for C function 'fprintf', expecting at least 2 parameters
60FFI\Exception: Passing incompatible argument 2 of C function 'fprintf', expecting 'char*', found PHP 'int'
61