bug54446_with_ini.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. ini_set("xsl.security_prefs", 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. ini_set("xsl.security_prefs", 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. #SET NO SECURITY PREFS with ini, but set them with ->setSecurityPrefs
  56. ini_set("xsl.security_prefs", XSL_SECPREF_NONE);
  57. $proc->setSecurityPrefs( XSL_SECPREF_WRITE_FILE | XSL_SECPREF_WRITE_NETWORK | XSL_SECPREF_CREATE_DIRECTORY);
  58. print $proc->transformToXML( $dom );
  59. if (file_exists($outputfile)) {
  60. print "$outputfile exists, but shouldn't!\n";
  61. } else {
  62. print "OK, no file created\n";
  63. }
  64. #don't throw a warning if both ini and through-the-method have the same value
  65. $proc->setSecurityPrefs(XSL_SECPREF_NONE);
  66. print $proc->transformToXML( $dom );
  67. if (file_exists($outputfile)) {
  68. print "OK, file exists\n";
  69. } else {
  70. print "$outputfile doesn't exist, but should!\n";
  71. }
  72. unlink($outputfile);
  73. --EXPECTF--
  74. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  75. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %s
  76. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  77. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  78. OK, no file created
  79. Deprecated: XSLTProcessor::transformToXml(): The xsl.security_prefs php.ini option is deprecated; use XsltProcessor->setSecurityPrefs() instead in %s on line %d
  80. OK, file exists
  81. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  82. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %s
  83. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  84. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  85. OK, no file created
  86. Deprecated: XSLTProcessor::transformToXml(): The xsl.security_prefs php.ini option is deprecated; use XsltProcessor->setSecurityPrefs() instead in %s on line %d
  87. Notice: XSLTProcessor::transformToXml(): The xsl.security_prefs php.ini was not used, since the XsltProcessor->setSecurityPrefs() method was used in %s on line %d
  88. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %s element output in %s on line %d
  89. Warning: XSLTProcessor::transformToXml(): File write for %s/bug54446test.txt refused in %s on line %s
  90. Warning: XSLTProcessor::transformToXml(): runtime error: file %s line %d element output in %s on line %d
  91. Warning: XSLTProcessor::transformToXml(): xsltDocumentElem: write rights for %s/bug54446test.txt denied in %s on line %d
  92. OK, no file created
  93. OK, file exists
  94. --CREDITS--
  95. Christian Stocker, chregu@php.net