| Conditions | 12 |
| Paths | 108 |
| Total Lines | 40 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 128 | public function checkSql($sql) |
||
| 129 | { |
||
| 130 | list($sql_wo_strings, $strings) = $this->separateStringsInSQL($sql) ; |
||
| 131 | |||
| 132 | // stage1: addslashes() processed or not |
||
| 133 | foreach ($this->doubtful_requests as $request) { |
||
| 134 | if (addslashes($request) != $request) { |
||
| 135 | if (stristr($sql, trim($request))) { |
||
| 136 | // check the request stayed inside of strings as whole |
||
| 137 | $ok_flag = false ; |
||
| 138 | foreach ($strings as $string) { |
||
| 139 | if (strstr($string, $request)) { |
||
| 140 | $ok_flag = true ; |
||
| 141 | break ; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | if (! $ok_flag) { |
||
| 145 | $this->injectionFound($sql) ; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // stage2: doubtful requests exists and outside of quotations ('or") |
||
| 152 | // $_GET['d'] = '1 UNION SELECT ...' |
||
| 153 | // NG: select a from b where c=$d |
||
| 154 | // OK: select a from b where c='$d_escaped' |
||
| 155 | // $_GET['d'] = '(select ... FROM)' |
||
| 156 | // NG: select a from b where c=(select ... from) |
||
| 157 | foreach ($this->doubtful_requests as $request) { |
||
| 158 | if (strstr($sql_wo_strings, trim($request))) { |
||
| 159 | $this->injectionFound($sql) ; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | // stage3: comment exists or not without quoted strings (too sensitive?) |
||
| 164 | if (preg_match('/(\/\*|\-\-|\#)/', $sql_wo_strings, $regs)) { |
||
| 165 | foreach ($this->doubtful_requests as $request) { |
||
| 166 | if (strstr($request, $regs[1])) { |
||
| 167 | $this->injectionFound($sql) ; |
||
| 168 | } |
||
| 192 |