Issues (3833)

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.

tests/phpunit/includes/wp-profiler.php (58 issues)

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
/*
4
A simple manually-instrumented profiler for WordPress.
5
6
This records basic execution time, and a summary of the actions and SQL queries run within each block.
7
8
start() and stop() must be called in pairs, for example:
9
10
function something_to_profile() {
11
	wppf_start(__FUNCTION__);
12
	do_stuff();
13
	wppf_stop();
14
}
15
16
Multiple profile blocks are permitted, and they may be nested.
17
18
*/
19
20
class WPProfiler
21
{
22
    var $stack;
23
    var $profile;
24
25
    /**
26
     * PHP5 constructor.
27
     */
28
    function __construct() 
29
    {
30
        $this->stack = array();
31
        $this->profile = array();
32
    }
33
34
    function start($name) 
35
    {
36
        $time = $this->microtime();
37
38
        if (!$this->stack) {
0 ignored issues
show
Expected 1 space before "!"; 0 found
Loading history...
Expected 1 space after "!"; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
39
            // log all actions and filters
40
            add_filter('all', array($this, 'log_filter'));
41
        }
42
43
        // reset the wpdb queries log, storing it on the profile stack if necessary
44
        global $wpdb;
45
        if ($this->stack) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
46
            $this->stack[count($this->stack)-1]['queries'] = $wpdb->queries;
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Expected 1 space before "-"; 0 found
Loading history...
47
        }
48
        $wpdb->queries = array();
49
50
        global $wp_object_cache;
51
52
        $this->stack[] = array(
53
         'start' => $time,
54
         'name' => $name,
55
         'cache_cold_hits' => $wp_object_cache->cold_cache_hits,
56
         'cache_warm_hits' => $wp_object_cache->warm_cache_hits,
57
         'cache_misses' => $wp_object_cache->cache_misses,
58
         'cache_dirty_objects' => $this->_dirty_objects_count($wp_object_cache->dirty_objects),
59
         'actions' => array(),
60
         'filters' => array(),
61
         'queries' => array(),
62
        );
63
64
    }
65
66
    function stop() 
67
    {
68
        $item = array_pop($this->stack);
69
        $time = $this->microtime($item['start']);
70
        $name = $item['name'];
71
72
        global $wpdb;
73
        $item['queries'] = $wpdb->queries;
74
        global $wp_object_cache;
75
76
        $cache_dirty_count = $this->_dirty_objects_count($wp_object_cache->dirty_objects);
77
        $cache_dirty_delta = $this->array_sub($cache_dirty_count, $item['cache_dirty_objects']);
78
79
        if (isset($this->profile[$name])) {
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
No space before closing parenthesis is prohibited
Loading history...
80
            $this->profile[$name]['time'] += $time;
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
81
            $this->profile[$name]['calls'] ++;
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
82
            $this->profile[$name]['cache_cold_hits'] += ($wp_object_cache->cold_cache_hits - $item['cache_cold_hits']);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
83
            $this->profile[$name]['cache_warm_hits'] += ($wp_object_cache->warm_cache_hits - $item['cache_warm_hits']);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
84
            $this->profile[$name]['cache_misses'] += ($wp_object_cache->cache_misses - $item['cache_misses']);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
85
            $this->profile[$name]['cache_dirty_objects'] = array_add($this->profile[$name]['cache_dirty_objects'], $cache_dirty_delta);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
86
            $this->profile[$name]['actions'] = array_add($this->profile[$name]['actions'], $item['actions']);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
87
            $this->profile[$name]['filters'] = array_add($this->profile[$name]['filters'], $item['filters']);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
88
            $this->profile[$name]['queries'] = array_add($this->profile[$name]['queries'], $item['queries']);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
89
            // $this->_query_summary($item['queries'], $this->profile[$name]['queries']);
90
91
        } else {
92
            $queries = array();
93
            $this->_query_summary($item['queries'], $queries);
94
            $this->profile[$name] = array(
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
95
             'time' => $time,
96
             'calls' => 1,
97
             'cache_cold_hits' => ($wp_object_cache->cold_cache_hits - $item['cache_cold_hits']),
98
             'cache_warm_hits' => ($wp_object_cache->warm_cache_hits - $item['cache_warm_hits']),
99
             'cache_misses' => ($wp_object_cache->cache_misses - $item['cache_misses']),
100
             'cache_dirty_objects' => $cache_dirty_delta,
101
             'actions' => $item['actions'],
102
             'filters' => $item['filters'],
103
            // 				'queries' => $item['queries'],
104
             'queries' => $queries,
105
            );
106
        }
107
108
        if (!$this->stack) {
0 ignored issues
show
Expected 1 space before "!"; 0 found
Loading history...
Expected 1 space after "!"; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
109
            remove_filter('all', array($this, 'log_filter'));
110
        }
111
    }
112
113
    function microtime($since = 0.0) 
114
    {
115
        list($usec, $sec) = explode(' ', microtime());
116
        return (float)$sec + (float)$usec - $since;
0 ignored issues
show
No space after closing casting parenthesis is prohibited
Loading history...
117
    }
118
119
    function log_filter($tag) 
120
    {
121
        if ($this->stack) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
122
            global $wp_actions;
123
            if ($tag == end($wp_actions)) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
124
                @$this->stack[count($this->stack)-1]['actions'][$tag] ++;
0 ignored issues
show
Silencing errors is discouraged
Loading history...
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Expected 1 space before "-"; 0 found
Loading history...
125
            } else {
126
                @$this->stack[count($this->stack)-1]['filters'][$tag] ++;
0 ignored issues
show
Silencing errors is discouraged
Loading history...
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Expected 1 space before "-"; 0 found
Loading history...
127
            }
128
        }
129
        return $arg;
130
    }
131
132
    function log_action($tag) 
133
    {
134
        if ($this->stack) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
135
              @$this->stack[count($this->stack)-1]['actions'][$tag] ++;
0 ignored issues
show
Silencing errors is discouraged
Loading history...
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Expected 1 space before "-"; 0 found
Loading history...
136
        }
137
    }
138
139
    function _current_action() 
140
    {
141
        global $wp_actions;
142
        return $wp_actions[count($wp_actions)-1];
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Expected 1 space before "-"; 0 found
Loading history...
143
    }
144
145
    function results() 
146
    {
147
        return $this->profile;
148
    }
149
150
    function _query_summary($queries, &$out) 
151
    {
152
        foreach ($queries as $q) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
153
            $sql = $q[0];
154
            $sql = preg_replace('/(WHERE \w+ =) \d+/', '$1 x', $sql);
155
            $sql = preg_replace('/(WHERE \w+ =) \'\[-\w]+\'/', '$1 \'xxx\'', $sql);
156
157
            @$out[$sql] ++;
0 ignored issues
show
Silencing errors is discouraged
Loading history...
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
158
        }
159
        asort($out);
160
        return;
161
    }
162
163
    function _query_count($queries) 
164
    {
165
        // this requires the savequeries patch at https://core.trac.wordpress.org/ticket/5218
166
        $out = array();
167
        foreach ($queries as $q) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
168
            if (empty($q[2])) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
169
                @$out['unknown'] ++;
0 ignored issues
show
Silencing errors is discouraged
Loading history...
170
            } else {
171
                @$out[$q[2]] ++;
0 ignored issues
show
Silencing errors is discouraged
Loading history...
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
172
            }
173
        }
174
        return $out;
175
    }
176
177
    function _dirty_objects_count($dirty_objects) 
178
    {
179
        $out = array();
180
        foreach (array_keys($dirty_objects) as $group) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
181
              $out[$group] = count($dirty_objects[$group]);
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
182
        }
183
        return $out;
184
    }
185
186
    function array_add($a, $b) 
187
    {
188
        $out = $a;
189
        foreach (array_keys($b) as $key) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
190
            if (array_key_exists($key, $out)) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
191
                $out[$key] += $b[$key];
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
192
            }
193
        }
194
        else {
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ELSE
Loading history...
195
            $out[$key] = $b[$key];
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
196
        }
197
        return $out;
198
    }
199
200
    function array_sub($a, $b) 
201
    {
202
        $out = $a;
203
        foreach (array_keys($b) as $key) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
204
            if (array_key_exists($key, $b)) {
0 ignored issues
show
No space before closing parenthesis is prohibited
Loading history...
205
                $out[$key] -= $b[$key];
0 ignored issues
show
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
206
            }
207
        }
208
        return $out;
209
    }
210
211
    function print_summary() 
212
    {
213
        $results = $this->results();
214
215
        printf("\nname                      calls   time action filter   warm   cold misses  dirty\n");
216
        foreach ($results as $name=>$stats) {
0 ignored issues
show
Expected 1 space before "=>"; 0 found
Loading history...
Expected 1 space after "=>"; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
217
            printf("%24.24s %6d %6.4f %6d %6d %6d %6d %6d %6d\n", $name, $stats['calls'], $stats['time'], array_sum($stats['actions']), array_sum($stats['filters']), $stats['cache_warm_hits'], $stats['cache_cold_hits'], $stats['cache_misses'], array_sum($stats['cache_dirty_objects']));
218
        }
219
    }
220
}
221
222
global $wppf;
223
$wppf = new WPProfiler();
224
225
function wppf_start($name) 
226
{
227
    $GLOBALS['wppf']->start($name);
228
}
229
230
function wppf_stop() 
231
{
232
    $GLOBALS['wppf']->stop();
233
}
234
235
function wppf_results() 
236
{
237
    return $GLOBALS['wppf']->results();
238
}
239
240
function wppf_print_summary() 
241
{
242
    $GLOBALS['wppf']->print_summary();
243
}
244
245
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...