splitPos returns the index where path should be split based on splitPath. example: if splitPath is [".php"] "/path/to/script.php/some/path": ("/path/to/script.php", "/some/path") Matching is strictly ASCII case-insensitive. Bytes >= utf8.RuneSelf in path never match any split entry: split strings a
(path string, splitPath []string)
| 243 | // upload a file whose name contains such code points and have it served as |
| 244 | // PHP. See GHSA-3g8v-8r37-cgjm and GHSA-v4h7-cj44-8fc8. |
| 245 | func splitPos(path string, splitPath []string) int { |
| 246 | if len(splitPath) == 0 { |
| 247 | return 0 |
| 248 | } |
| 249 | |
| 250 | pathLen := len(path) |
| 251 | |
| 252 | for _, split := range splitPath { |
| 253 | splitLen := len(split) |
| 254 | if splitLen == 0 || splitLen > pathLen { |
| 255 | continue |
| 256 | } |
| 257 | |
| 258 | for i := 0; i <= pathLen-splitLen; i++ { |
| 259 | match := true |
| 260 | for j := 0; j < splitLen; j++ { |
| 261 | c := path[i+j] |
| 262 | if c >= utf8.RuneSelf { |
| 263 | match = false |
| 264 | |
| 265 | break |
| 266 | } |
| 267 | |
| 268 | if 'A' <= c && c <= 'Z' { |
| 269 | c += 'a' - 'A' |
| 270 | } |
| 271 | |
| 272 | if c != split[j] { |
| 273 | match = false |
| 274 | |
| 275 | break |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | if match { |
| 280 | return i + splitLen |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | return -1 |
| 286 | } |
| 287 | |
| 288 | // go_update_request_info updates the sapi_request_info struct |
| 289 | // See: https://github.com/php/php-src/blob/345e04b619c3bc11ea17ee02cdecad6ae8ce5891/main/SAPI.h#L72 |
no outgoing calls