コード例 #1
0
/**
 * calls $function for every element in $array recursively
 *
 * this function is protected against deep recursion attack CVE-2006-1549,
 * 1000 seems to be more than enough
 *
 * @param array  &$array             array to walk
 * @param string $function           function to call for every array element
 * @param bool   $apply_to_keys_also whether to call the function for the keys also
 *
 * @return void
 *
 * @see http://www.php-security.org/MOPB/MOPB-02-2007.html
 * @see http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2006-1549
 */
function PMA_arrayWalkRecursive(&$array, $function, $apply_to_keys_also = false)
{
    static $recursive_counter = 0;
    if (++$recursive_counter > 1000) {
        //PMA_fatalError(__('possible deep recursion attack'));
        die('possible deep recursion attack');
    }
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            PMA_arrayWalkRecursive($array[$key], $function, $apply_to_keys_also);
        } else {
            $array[$key] = $function($value);
        }
        if ($apply_to_keys_also && is_string($key)) {
            $new_key = $function($key);
            if ($new_key != $key) {
                $array[$new_key] = $array[$key];
                unset($array[$key]);
            }
        }
    }
    $recursive_counter--;
}
コード例 #2
0
ファイル: common.inc.php プロジェクト: mi-squared/openemr
    // because another application for the same domain could have set
    // a cookie (with a compatible path) that overrides a variable
    // we expect from GET or POST.
    // We'll refer to cookies explicitly with the $_COOKIE syntax.
    $_REQUEST = array_merge($_GET, $_POST);
}
// end check if a subform is submitted
/**
 * This setting was removed in PHP 5.4, but get_magic_quotes_gpc
 * always returns False since then.
 */
if (get_magic_quotes_gpc()) {
    PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
    PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
    PMA_arrayWalkRecursive($_COOKIE, 'stripslashes', true);
    PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
}
/**
 * check timezone setting
 * this could produce an E_STRICT - but only once,
 * if not done here it will produce E_STRICT on every date/time function
 * (starting with PHP 5.3, this code can produce E_WARNING rather than
 *  E_STRICT)
 *
 */
date_default_timezone_set(@date_default_timezone_get());
/******************************************************************************/
/* parsing configuration file                  LABEL_parsing_config_file      */
/**
 * We really need this one!
 */
コード例 #3
0
/**
 * recursively check if variable is empty
 *
 * @param mixed $value the variable
 *
 * @return bool true if empty
 */
function PMA_emptyRecursive($value)
{
    $empty = true;
    if (is_array($value)) {
        PMA_arrayWalkRecursive($value, function ($item) use(&$empty) {
            $empty = $empty && empty($item);
        });
    } else {
        $empty = empty($value);
    }
    return $empty;
}
コード例 #4
0
 /**
  * Test for PMA_arrayWalkRecursive
  *
  * @return void
  */
 function testWalkRecursiveApplyToKeysStripSlashes()
 {
     $arr = array("key\\1" => 'v\\\\al1', 'k\\ey2' => array('s\\\\key1' => 'sval\\1', 's\\k\\ey2' => 's\\v\\al2'), 'key3' => 'val3');
     $second = $arr;
     $target = array("key1" => 'v\\al1', 'key2' => array('s\\key1' => 'sval1', 'skey2' => 'sval2'), 'key3' => 'val3');
     PMA_arrayWalkRecursive($arr, 'stripslashes', true);
     $this->assertEquals($arr, $target);
     PMA_arrayWalkRecursive($second, 'stripslashes', true);
     $this->assertEquals($second, $target);
 }
コード例 #5
0
ファイル: common.lib.php プロジェクト: a195474368/ejiawang
/**
 * calls $function vor every element in $array recursively
 *
 * @param   array   $array      array to walk
 * @param   string  $function   function to call for every array element
 */
function PMA_arrayWalkRecursive(&$array, $function, $apply_to_keys_also = false)
{
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            PMA_arrayWalkRecursive($array[$key], $function, $apply_to_keys_also);
        } else {
            $array[$key] = $function($value);
        }
        if ($apply_to_keys_also && is_string($key)) {
            $new_key = $function($key);
            if ($new_key != $key) {
                $array[$new_key] = $array[$key];
                unset($array[$key]);
            }
        }
    }
}