bug54446.phpt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --TEST--
  2. Bug #54446 (Arbitrary file creation via libxslt 'output' extension)
  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. # TRASNFORM & 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. # TRASNFORM & 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. --EXPECTF--
  56. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  57. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %s
  58. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  59. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  60. OK, no file created
  61. OK, file exists
  62. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  63. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %s
  64. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  65. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  66. OK, no file created
  67. --CREDITS--
  68. Christian Stocker, chregu@php.net