This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Move user's data directories from using username to registration date |
||
5 | */ |
||
6 | |||
7 | /** |
||
8 | * Generates a file matrix like Elgg 1.0 did |
||
9 | * |
||
10 | * @param string $username Username of user |
||
11 | * |
||
12 | * @return string File matrix path |
||
13 | */ |
||
14 | function file_matrix_1_0($username) { |
||
15 | $matrix = ""; |
||
16 | |||
17 | $len = strlen($username); |
||
18 | if ($len > 5) { |
||
19 | $len = 5; |
||
20 | } |
||
21 | |||
22 | for ($n = 0; $n < $len; $n++) { |
||
23 | if (ctype_alnum($username[$n])) { |
||
24 | $matrix .= $username[$n] . "/"; |
||
25 | } |
||
26 | } |
||
27 | |||
28 | return $matrix . $username . "/"; |
||
29 | } |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Generate a file matrix like Elgg 1.1, 1.2 and 1.5 |
||
34 | * |
||
35 | * @param string $filename The filename |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | function file_matrix_1_1($filename) { |
||
40 | $matrix = ""; |
||
41 | |||
42 | $name = $filename; |
||
43 | $filename = mb_str_split($filename); |
||
44 | if (!$filename) { |
||
45 | return false; |
||
46 | } |
||
47 | |||
48 | $len = count($filename); |
||
49 | if ($len > 5) { |
||
50 | $len = 5; |
||
51 | } |
||
52 | |||
53 | for ($n = 0; $n < $len; $n++) { |
||
54 | $matrix .= $filename[$n] . "/"; |
||
55 | } |
||
56 | |||
57 | return $matrix . $name . "/"; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Handle splitting multibyte strings |
||
62 | * |
||
63 | * @param string $string String to split. |
||
64 | * @param string $charset Charset to use. |
||
65 | * |
||
66 | * @return array|false |
||
67 | */ |
||
68 | View Code Duplication | function mb_str_split($string, $charset = 'UTF8') { |
|
69 | if (is_callable('mb_substr')) { |
||
70 | $length = mb_strlen($string); |
||
71 | $array = array(); |
||
72 | |||
73 | while ($length) { |
||
74 | $array[] = mb_substr($string, 0, 1, $charset); |
||
75 | $string = mb_substr($string, 1, $length, $charset); |
||
76 | |||
77 | $length = mb_strlen($string); |
||
78 | } |
||
79 | |||
80 | return $array; |
||
81 | } else { |
||
82 | return str_split($string); |
||
83 | } |
||
84 | |||
85 | return false; |
||
0 ignored issues
–
show
|
|||
86 | } |
||
87 | |||
88 | |||
89 | /** |
||
90 | * 1.6 style file matrix |
||
91 | * |
||
92 | * @param string $filename The filename |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | function file_matrix_1_6($filename) { |
||
97 | $invalid_fs_chars = '*\'\\/"!$%^&*.%(){}[]#~?<>;|¬`@-+='; |
||
98 | |||
99 | $matrix = ""; |
||
100 | |||
101 | $name = $filename; |
||
102 | $filename = mb_str_split($filename); |
||
103 | if (!$filename) { |
||
104 | return false; |
||
105 | } |
||
106 | |||
107 | $len = count($filename); |
||
108 | if ($len > 5) { |
||
109 | $len = 5; |
||
110 | } |
||
111 | |||
112 | for ($n = 0; $n < $len; $n++) { |
||
113 | |||
114 | // Prevent a matrix being formed with unsafe characters |
||
115 | $char = $filename[$n]; |
||
116 | if (strpos($invalid_fs_chars, $char) !== false) { |
||
117 | $char = '_'; |
||
118 | } |
||
119 | |||
120 | $matrix .= $char . "/"; |
||
121 | } |
||
122 | |||
123 | return $matrix . $name . "/"; |
||
124 | } |
||
125 | |||
126 | |||
127 | /** |
||
128 | * Scans a directory and moves any files from $from to $to |
||
129 | * preserving structure and handling existing paths. |
||
130 | * Will no overwrite files in $to. |
||
131 | * |
||
132 | * TRAILING SLASHES REQUIRED. |
||
133 | * |
||
134 | * @param string $from From dir. |
||
135 | * @param string $to To dir. |
||
136 | * @param bool $move True to move, false to copy. |
||
137 | * @param string $preference to|from If file collisions, which dir has preference. |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | function merge_directories($from, $to, $move = false, $preference = 'to') { |
||
142 | if (!$entries = scandir($from)) { |
||
143 | return false; |
||
144 | } |
||
145 | |||
146 | // character filtering needs to be elsewhere. |
||
147 | if (!is_dir($to)) { |
||
148 | mkdir($to, 0700, true); |
||
149 | } |
||
150 | |||
151 | if ($move === true) { |
||
152 | $f = 'rename'; |
||
153 | } else { |
||
154 | $f = 'copy'; |
||
155 | } |
||
156 | |||
157 | foreach ($entries as $entry) { |
||
158 | if ($entry == '.' || $entry == '..') { |
||
159 | continue; |
||
160 | } |
||
161 | |||
162 | $from_path = $from . $entry; |
||
163 | $to_path = $to . $entry; |
||
164 | |||
165 | // check to see if the path exists and is a dir, if so, recurse. |
||
166 | if (is_dir($from_path) && is_dir($to_path)) { |
||
167 | $from_path .= '/'; |
||
168 | $to_path .= '/'; |
||
169 | merge_directories($from_path, $to_path, $move, $preference); |
||
170 | |||
171 | // since it's a dir that already exists we don't need to move it |
||
172 | continue; |
||
173 | } |
||
174 | |||
175 | // only move if target doesn't exist or if preference is for the from dir |
||
176 | if (!file_exists($to_path) || $preference == 'from') { |
||
177 | |||
178 | if ($f($from_path, $to_path)) { |
||
179 | //elgg_dump("Moved/Copied $from_path to $to_path"); |
||
180 | } |
||
181 | } else { |
||
182 | //elgg_dump("Ignoring $from_path -> $to_path"); |
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Create a 1.7 style user file matrix based upon date. |
||
189 | * |
||
190 | * @param int $guid Guid of owner |
||
191 | * |
||
192 | * @return string File matrix path |
||
193 | */ |
||
194 | View Code Duplication | function user_file_matrix($guid) { |
|
195 | // lookup the entity |
||
196 | $user = get_entity($guid); |
||
197 | if ($user->type != 'user') { |
||
198 | // only to be used for user directories |
||
199 | return FALSE; |
||
200 | } |
||
201 | |||
202 | $time_created = date('Y/m/d', $user->time_created); |
||
203 | return "$time_created/$user->guid/"; |
||
204 | } |
||
205 | |||
206 | global $ENTITY_CACHE, $CONFIG; |
||
207 | /** |
||
208 | * Upgrade file locations |
||
209 | */ |
||
210 | $users = mysql_query("SELECT guid, username |
||
211 | FROM {$CONFIG->dbprefix}users_entity WHERE username != ''"); |
||
212 | View Code Duplication | while ($user = mysql_fetch_object($users)) { |
|
213 | $ENTITY_CACHE = array(); |
||
214 | |||
215 | $to = $CONFIG->dataroot . user_file_matrix($user->guid); |
||
216 | foreach (array('1_0', '1_1', '1_6') as $version) { |
||
217 | $function = "file_matrix_$version"; |
||
218 | $from = $CONFIG->dataroot . $function($user->username); |
||
219 | merge_directories($from, $to, $move = TRUE, $preference = 'from'); |
||
220 | } |
||
221 | } |
||
222 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.