bug77706.phpt 1.5 KB

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