bug54446.phpt 2.4 KB

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