]> granicus.if.org Git - php/commitdiff
Fix #77431 SplFileInfo::__construct() accepts NUL bytes
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 9 Jan 2019 13:26:18 +0000 (14:26 +0100)
committerStanislav Malyshev <stas@php.net>
Mon, 4 Mar 2019 02:23:46 +0000 (18:23 -0800)
`SplFileInfo::__construct()` has to expect a path instead of a string,
analogous to `SplFileObject::__construct()`.

ext/spl/spl_directory.c
ext/spl/tests/bug77431.phpt [new file with mode: 0644]

index fc4001ae1f8c09b1ab4f41bcceb868e1f930f383..748b1549b54c6ccda08987dc7a509ea9a2b12ae2 100644 (file)
@@ -1110,7 +1110,7 @@ SPL_METHOD(SplFileInfo, __construct)
        char *path;
        size_t len;
 
-       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &path, &len) == FAILURE) {
+       if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "p", &path, &len) == FAILURE) {
                return;
        }
 
diff --git a/ext/spl/tests/bug77431.phpt b/ext/spl/tests/bug77431.phpt
new file mode 100644 (file)
index 0000000..eb1ca96
--- /dev/null
@@ -0,0 +1,9 @@
+--TEST--
+Bug #77431 (SplFileInfo::__construct() accepts NUL bytes)
+--FILE--
+<?php
+new SplFileInfo("bad\0good");
+?>
+--EXPECTF--
+Fatal error: Uncaught TypeError: SplFileInfo::__construct() expects parameter 1 to be a valid path, string given in %s:%d
+Stack trace:%A
\ No newline at end of file