PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » PEAR » PEAR » Bug #6269

System::which() returns silliness if passed null

Details

Submitted2005-12-16 19:58 UTC
Fromcconstantine at php dot net
Assignedcellog
StatusClosed
PackagePEAR
PHP Version4.3.11
Roadmaps(Not assigned)

Comments

[2005-12-16 19:58 UTC] cconstantine at php dot net

Description:
------------
System::which(null) returns the first element in the envvar
PATH. Would be wise to test the arg for is_string() and
nonempty, and return early if caller is violating the API.

Diff for CV Id: System.php,v 1.51 2005/11/16 03:28:56 cellog
Exp

--- System.php.orig 2005-12-16 14:55:38.000000000 -0500
+++ System.php.new 2005-12-16 14:56:47.000000000 -0500
@@ -447,6 +447,11 @@
*/
function which($program, $fallback = false)
{
+ // enforce API
+ if (!is_string($program) || '' == $program) {
+ return $fallback;
+ }
+
// avaible since 4.3.0RC2
if (defined('PATH_SEPARATOR')) {
$path_delim = PATH_SEPARATOR;

Test script:
---------------
<?php

require 'System.php';

$result = System::which(null, false);

if ( false === $result ) {
print("got false");
} else {
print $result;
}

?>

Expected result:
----------------
$result should be false.

Actual result:
--------------
prints "/bin/" (which is the first element in my PATH envvar.)