|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8921 Require() function : filename string not terminated correctly internally
Submitted: 2001-01-25 19:18 UTC Modified: 2001-03-16 17:40 UTC
From: mahony at cwa dot co dot nz Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.4pl1 OS: Linux Debian Potato 2.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
38 - 18 = ?
Subscribe to this entry?

 [2001-01-25 19:18 UTC] mahony at cwa dot co dot nz

I've found what appears to be a reproducable bug with random effects.

When I pass a seemingly perfect filename string to the Require() function it comes back (2 times out of 3) with extra characters at the end, causing the require function to fail to find the file. The characters are illustrated below, and many seem to be non-alphabetic. It looks like a C string buffer overflow problem (ie: the length of the string has been enlarged by a random amount between about 2 and 5 characters, and it's picking up additional characters directly out of memory).

This is the code that is executing :

if("" == $inc_filename) {
  print("You have to enter a filename first !");
else  // NON-Blank include filename
  print("Filename = ".$inc_filename);   // <<<<< Note : here the filename displays fine

  require( $inc_filename );   // <<<<< Note : here it is corrupted

These are the output lines I got  (note the crap at the end of the filename in the error message) :

 Filename = inc/britz/
Fatal error: Failed opening required 'inc/britz/'  
(include_path='.:/usr/local/lib/php') in
/home/ekiwi/public_html/layout.php on line 199

  Filename = inc/britz/
 Fatal error: Failed opening required 'inc/britz/'
 (include_path='.:/usr/local/lib/php') in
 on line 199

 THEN IT WAS OK TWICE, followed by

 Filename = inc/britz/
Fatal error: Failed opening required 'inc/britz/'A'
 (include_path='.:/usr/local/lib/php') in
 on line 199

 Filename = inc/britz/
Fatal error: Failed opening required 'inc/britz/'
 (include_path='.:/usr/local/lib/php') in
 on line 199

To see this in action see :

Be aware that it works perfectly about a third of the time, so keep pressing the refresh button on your browser until it throws the error. 

We're running Linux kernal 2.2.18

Our PHP config details are available at :

Hope this helps,

Simon Mahony,
Technical Director,
CWA New Media,
New Zealand.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-06 20:55 UTC] mahony at cwa dot co dot nz
I've since found that the problem only manifests itself when variables are used as parameters to Require().
$filename = "test.html";

If a string constant is used as a parameter the function performs correctly.

Consequently I was able to solve my problem by using PHPs "evaluate variable within string" trick -
$filename = "test.html";

 [2001-03-16 17:40 UTC]
Can't reproduce with latest CVS. Try the latest CVS snapshot
from and reopen if problem persists.


PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed May 27 04:01:26 2020 UTC