php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #77431
Patch fix-77431 revision 2019-01-09 13:29 UTC by cmb@php.net

Patch fix-77431 for SPL related Bug #77431

Patch version 2019-01-09 13:29 UTC

Return to Bug #77431 | Download this patch
Patch Revisions:

Developer: cmb@php.net

From 6d0b8bcca366e51cc84fdedfb2e2cbfa31657737 Mon Sep 17 00:00:00 2001
From: "Christoph M. Becker" <cmbecker69@gmx.de>
Date: Wed, 9 Jan 2019 14:26:18 +0100
Subject: [PATCH] Fix #77431 SplFileInfo::__construct() accepts NUL bytes

`SplFileInfo::__construct()` has to expect a path instead of a string,
analogous to `SplFileObject::__construct()`.
---
 ext/spl/spl_directory.c     | 2 +-
 ext/spl/tests/bug77431.phpt | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 ext/spl/tests/bug77431.phpt

diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
index fc4001ae1f..748b1549b5 100644
--- a/ext/spl/spl_directory.c
+++ b/ext/spl/spl_directory.c
@@ -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
index 0000000000..eb1ca96b75
--- /dev/null
+++ b/ext/spl/tests/bug77431.phpt
@@ -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
-- 
2.17.0.windows.1

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 23:01:34 2024 UTC