Issues (1752)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

func/array.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Funcs about array
4
 *
5
 * @package		fwolflib
6
 * @subpackage	func
7
 * @copyright   Copyright © 2010-2011, Fwolf
8
 * @author      Fwolf <[email protected]>
9
 * @since		2010-01-25
10
 */
11
12
13
require_once(dirname(__FILE__) . '/../fwolflib.php');
14
require_once(FWOLFLIB . 'func/string.php');
15
16
17
/**
18
 * Add value to array by key, if key not exist, init with value.
19
 *
20
 * @deprecated      Use Fwlib\Util\ArrayUtil::increaseByKey()
21
 * @param	array	&$ar_srce
22
 * @param	string	$key
23
 * @param	mixed	$val		Default val if not assigned.
24
 */
25
function ArrayAdd (&$ar_srce, $key, $val = 1) {
26 View Code Duplication
	if (isset($ar_srce[$key])) {
27
		if (is_string($val))
28
			$ar_srce[$key] .= $val;
29
		else
30
			$ar_srce[$key] += $val;
31
	}
32
	else
33
		$ar_srce[$key] = $val;
34
35
	return $ar_srce;
36
} // end of func ArrayAdd
37
38
39
/**
40
 * Eval string by replace tag with array value by index
41
 *
42
 * @deprecated      Use Fwlib\Util\StringUtil::evalWithTag()
43
 * @param	string	$s_eval
44
 * @param	array	$ar		Data array, must have assoc index.
45
 * @return	mixed
46
 */
47
function ArrayEval ($s_eval, $ar = array()) {
48
	if (empty($s_eval))
49
		return null;
50
	$s_eval = trim($s_eval);
51
52
	// Replace tag with array value
53
	if (!empty($ar))
54
		foreach ($ar as $k => $v)
55
			$s_eval = str_replace('{' . $k . '}', $v, $s_eval);
56
57
	// Add tailing ';'
58
	if (';' != substr($s_eval, -1))
59
		$s_eval .= ';';
60
61
	$rs = eval($s_eval);
62
63
	if (is_null($rs))
64
		// Need add return in eval str
65
		$rs = eval('return ' . $s_eval);
66
67
	return $rs;
68
} // end of func ArrayEval
69
70
71
/**
72
 * Insert data to assigned position in srce array by assoc key.
73
 *
74
 * Can also use on numeric indexed array.
75
 *
76
 * If key in ins array already exists in srce array, according ins pos
77
 * and original pos of the key, the later value overwrite before one,
78
 * and it pos also leave as the before one. So if you can't use this
79
 * to move item in array forward or backward.
80
 *
81
 * @deprecated      Use Fwlib\Util\ArrayUtil::insert()
82
 * @param	array	&$ar_srce
83
 * @param	mixed	$idx		Position idx, append @ end if not found.
84
 * @param	array	$ar_ins		Array to insert, can have multi item.
85
 * @param	integer	$i_pos		-1=insert before index, 0=replace index
86
 * 		1=insert after index, default=1.
87
 * 		If abs($i_pos)>0, eg: 2 means insert after 2-1 pos after $idx.
88
 * 		a    b     c    d   e		Index
89
 * 		  -2   -1  0  1   2			Insert position by $i_pos
90
 * @return	array
91
 */
92
function ArrayInsert (&$ar_srce, $idx, $ar_ins, $i_pos = 1) {
93
	if (empty($ar_ins))
94
		return $ar_srce;
95
96
	// Find ins position
97
	$ar_key = array_keys($ar_srce);
98
	$i_pos_ins = array_search($idx, $ar_key, true);
99
	if (false === $i_pos_ins) {
100
		// Idx not found, append.
101
		foreach ($ar_ins as $k => $v)
102
			if (isset($ar_srce[$k]))
103
				$ar_srce[] = $v;
104
			else
105
				$ar_srce[$k] = $v;
106
		return $ar_srce;
107
	}
108
109
	// Chg ins position by $i_pos
110
	$i_pos_ins += $i_pos + (0 >= $i_pos ? 1 : 0);
111
	$i_cnt_srce = count($ar_srce);
112
	if (0 > $i_pos_ins)
113
		$i_pos_ins = 0;
114
	if ($i_cnt_srce < $i_pos_ins)
115
		$i_pos_ins = $i_cnt_srce;
116
117
	// Loop to gen result ar
118
	$ar_rs = array();
119
	$i_srce = -1;		// Need loop to $i_cnt_srce, not $i_cnt_srce-1
120
	while ($i_srce < $i_cnt_srce) {
121
		$i_srce ++;
122
		if ($i_pos_ins == $i_srce) {
123
			// Got insert position
124
			foreach ($ar_ins as $k => $v)
125
				// Notice: if key exists, will be overwrite.
126
				$ar_rs[$k] = $v;
127
		}
128
129
		if ($i_srce == $i_cnt_srce)
130
			continue;
131
		// Insert original data
132
		$k = $ar_key[$i_srce];
133
		$ar_rs[$k] = $ar_srce[$k];
134
	}
135
	// Pos = 0, replace
136
	if (0 == $i_pos)
137
		unset($ar_rs[$ar_key[$i_pos_ins - 1]]);
138
139
	$ar_srce = $ar_rs;
140
	return $ar_srce;
141
} // end of func ArrayInsert
142
143
144
/**
145
 * Read value from array.
146
 *
147
 * @deprecated      Use Fwlib\Util\ArrayUtil::getIdx(), getEdx()
148
 * @param	array	$ar
149
 * @param	mixed	$key
150
 * @param	mixed	$val_default
151
 * @return	mixed
152
 */
153
function ArrayRead($ar, $key, $val_default = null) {
154
	if (isset($ar[$key]))
155
		$val_return = $ar[$key];
156
	elseif (!is_null($val_default))
157
		$val_return = $val_default;
158
	else
159
		$val_return = null;
160
161
    return $val_return;
162
} // end of func ArrayRead
163
164
165
/**
166
 * Sort array by one of its 2lv keys, and maintain assoc index.
167
 *
168
 * @deprecated      Use Fwlb\Util\ArrayUtil::sortByLevel2() or array_multisort()
169
 * @param	array	&$ar_srce	Array to be sort
170
 * @param	mixed	$key
171
 * @param	mixed	$b_asc		True = asc/false = desc, or use str.
172
 * @param	mixed	$joker		Use when val of key isn't set.
173
 * @return	array
174
 */
175
function ArraySort (&$ar_srce, $key, $b_asc = true, $joker = '') {
176
	$ar_val = array();
177
	foreach ($ar_srce as $k => $v)
178
		$ar_val[$k] = isset($v[$key]) ? $v[$key] : $joker;
179
180
	if (true === $b_asc || 'asc' == $b_asc)
181
		asort($ar_val);
182
	else
183
		arsort($ar_val);
184
185
	// Got currect order, write back.
186
	$ar_rs = array();
187
	foreach ($ar_val as $k => $v) {
188
		$ar_val[$k] = &$ar_srce[$k];
189
	}
190
191
	$ar_srce = $ar_val;
192
	return $ar_srce;
193
} // end of func ArraySort
194
195
196
/**
197
 * Filter an array by wildcard rules.
198
 *
199
 * Wildcard rules is a string include many part joined by ',',
200
 * each part can include * and ?, head by '+'(default) or '-',
201
 * they means find elements suit the rules in source array,
202
 * and add_to/remove_from result array.
203
 *
204
 * Parts operate sequence is by occur position in rules string.
205
 *
206
 * Rules example: a*, -*b, -??c, +?d*
207
 *
208
 * @deprecated      Use Fwlib\Util\ArrayUtil::searchByWildcard()
209
 * @param	array	$ar_srce	Source data.
210
 * @param	string	$rules		Wildcard rule string.
211
 * @return	array
212
 */
213
function FilterWildcard($ar_srce, $rules) {
214
	$ar_result = array();
215
216
	// Check srce ar
217
	if (empty($ar_srce))
218
		return $ar_result;
219
220
	// Read rules
221
	$ar_rule = explode(',', $rules);
222
	if (empty($ar_rule))
223
		return $ar_result;
224
225
	// Use rules
226
	foreach ($ar_rule as $rule) {
227
		$rule = trim($rule);
228
		// + or - ?
229
		if ('+' == $rule[0]) {
230
			$i_op = '+';
231
			$rule = substr($rule, 1);
232
		}
233
		elseif ('-' == $rule[0]) {
234
			$i_op = '-';
235
			$rule = substr($rule, 1);
236
		}
237
		else
238
			$i_op = '+';
239
240
		// Loop srce ar
241
		foreach ($ar_srce as $srce) {
242
			if (true == MatchWildcard($srce, $rule)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
243
				// Got element to +/-
244
				$i = array_search($srce, $ar_result);
245
				if ('+' == $i_op) {
246
					// Add to ar if not in it.
247
					if (false === $i)
248
						$ar_result = array_merge($ar_result, array($srce));
249
				}
250
				else {
251
					// Remove from ar if exists.
252
					if (! (false === $i))
253
						unset($ar_result[$i]);
254
				}
255
			}
256
		}
257
	}
258
259
	return $ar_result;
260
} // end of func FilterWildcard
261
262
263
?>
264