mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
Fix panic serving index file if HTTP request is malformed
This commit is contained in:
parent
b5906135c7
commit
14a8ffedd8
1 changed files with 4 additions and 0 deletions
|
@ -117,6 +117,10 @@ func (c ConfigSelector) Select(r *http.Request) (config HandlerConfig) {
|
||||||
// path separator, just like URLs. IndexFle handles path manipulation
|
// path separator, just like URLs. IndexFle handles path manipulation
|
||||||
// internally for systems that use different path separators.
|
// internally for systems that use different path separators.
|
||||||
func IndexFile(root http.FileSystem, fpath string, indexFiles []string) (string, bool) {
|
func IndexFile(root http.FileSystem, fpath string, indexFiles []string) (string, bool) {
|
||||||
|
if len(fpath) == 0 {
|
||||||
|
// https://caddy.community/t/panic-runtime-error-index-out-of-range/5781
|
||||||
|
fpath = "/"
|
||||||
|
}
|
||||||
if fpath[len(fpath)-1] != '/' || root == nil {
|
if fpath[len(fpath)-1] != '/' || root == nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue