bug54446_with_ini.phpt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --TEST--
  2. Bug #54446 (Arbitrary file creation via libxslt 'output' extension with php.ini setting)
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('xsl')) die("skip Extension XSL is required\n");
  6. ?>
  7. --FILE--
  8. <?php
  9. include("prepare.inc");
  10. $outputfile = dirname(__FILE__)."/bug54446test.txt";
  11. if (file_exists($outputfile)) {
  12. unlink($outputfile);
  13. }
  14. $sXsl = <<<EOT
  15. <xsl:stylesheet version="1.0"
  16. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  17. xmlns:sax="http://icl.com/saxon"
  18. extension-element-prefixes="sax">
  19. <xsl:template match="/">
  20. <sax:output href="$outputfile" method="text">
  21. <xsl:value-of select="'0wn3d via PHP and libxslt ...'"/>
  22. </sax:output>
  23. </xsl:template>
  24. </xsl:stylesheet>
  25. EOT;
  26. $xsl->loadXML( $sXsl );
  27. # START XSLT
  28. $proc->importStylesheet( $xsl );
  29. # TRASNFORM & PRINT
  30. print $proc->transformToXML( $dom );
  31. if (file_exists($outputfile)) {
  32. print "$outputfile exists, but shouldn't!\n";
  33. } else {
  34. print "OK, no file created\n";
  35. }
  36. #SET NO SECURITY PREFS
  37. $proc->setSecurityPrefs(XSL_SECPREF_NONE);
  38. # TRANSFORM & PRINT
  39. print $proc->transformToXML( $dom );
  40. if (file_exists($outputfile)) {
  41. print "OK, file exists\n";
  42. } else {
  43. print "$outputfile doesn't exist, but should!\n";
  44. }
  45. unlink($outputfile);
  46. #SET SECURITY PREFS AGAIN
  47. $proc->setSecurityPrefs(XSL_SECPREF_WRITE_FILE | XSL_SECPREF_WRITE_NETWORK | XSL_SECPREF_CREATE_DIRECTORY);
  48. # TRANSFORM & PRINT
  49. print $proc->transformToXML( $dom );
  50. if (file_exists($outputfile)) {
  51. print "$outputfile exists, but shouldn't!\n";
  52. } else {
  53. print "OK, no file created\n";
  54. }
  55. ?>
  56. --EXPECTF--
  57. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  58. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %d
  59. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  60. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  61. OK, no file created
  62. OK, file exists
  63. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  64. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %d
  65. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  66. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  67. OK, no file created
  68. --CREDITS--
  69. Christian Stocker, chregu@php.net