|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14425 extract() can overwrite $GLOBALS within a function context
Submitted: 2001-12-11 08:55 UTC Modified: 2001-12-12 10:54 UTC
From: philhassey at hotmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.0.6 OS: Linux (Mandrake 8.1)
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:
43 + 12 = ?
Subscribe to this entry?

 [2001-12-11 08:55 UTC] philhassey at hotmail dot com
//I did this:
function test()
// The script will overwrite the $GLOBALS variable
// I did not want it to overwrite the $GLOBALS variable

// Then in the global scope, I did this:$a=array("GLOBALS"=>"nothing");
//The script did not overwrite the $GLOBALS variable.
// It did what I wanted it to do.

By allowing the extract function to overwrite global variables within a function can lead to serious security holes.  Particularily if URL parameters are passed into a function that extracts them.  (And then if my function still expects GLOBALS to be legit, it could be passed false information.)

I suggest making extract unable to overwrite any global variables within a function.  ($GLOBALS, and any variables declared global $x, etc..) As a second measure it might be good to make extract more conservative in general by defaulting to EXTR_SKIP instead of EXTR_OVERWRITE

I can, of course, fix my own code for the time being to avoid this problem by using extract($params,EXTR_SKIP); However I think fixing the problem for PHP as a whole would help others as well.

Thank you.  Keep up the excellent work!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-11 09:22 UTC] philhassey at hotmail dot com
Similarily, this bug is also found in class methods.

class a
function test()
$a=new a();

// Both this and GLOBALS are overwritten by extract.
// I would have hoped that would not have happened.

 [2001-12-12 10:54 UTC]

"If extract_type is not specified, it is assumed to be EXTR_OVERWRITE. "

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 05 05:01:29 2024 UTC