bug69646.phpt 814 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Bug #69646 OS command injection vulnerability in escapeshellarg()
  3. --SKIPIF--
  4. <?php
  5. if( substr(PHP_OS, 0, 3) != "WIN" )
  6. die("skip.. Windows only");
  7. ?>
  8. --FILE--
  9. <?php
  10. $a = 'a\\';
  11. $b = 'b -c d\\';
  12. var_dump( $a, escapeshellarg($a) );
  13. var_dump( $b, escapeshellarg($b) );
  14. $helper_script = <<<SCRIPT
  15. <?php
  16. print( "--- ARG INFO ---\n" );
  17. var_dump( \$argv );
  18. SCRIPT;
  19. $script = __DIR__ . DIRECTORY_SEPARATOR . "arginfo.php";
  20. file_put_contents($script, $helper_script);
  21. $cmd = PHP_BINARY . " " . $script . " " . escapeshellarg($a) . " " . escapeshellarg($b);
  22. system($cmd);
  23. unlink($script);
  24. ?>
  25. --EXPECTF--
  26. string(2) "a\"
  27. string(5) ""a\\""
  28. string(7) "b -c d\"
  29. string(10) ""b -c d\\""
  30. --- ARG INFO ---
  31. array(3) {
  32. [0]=>
  33. string(%d) "%sarginfo.php"
  34. [1]=>
  35. string(2) "a\"
  36. [2]=>
  37. string(7) "b -c d\"
  38. }