avoid busy loops in bad path component (#19466)

use it in places where we are looking
for such bad path components.
This commit is contained in:
Harshavardhana
2024-04-10 18:08:52 -07:00
committed by GitHub
parent 35d8728990
commit 9b926f7dbe
2 changed files with 11 additions and 3 deletions

View File

@@ -310,6 +310,13 @@ func hasBadHost(host string) error {
// Check if the incoming path has bad path components,
// such as ".." and "."
func hasBadPathComponent(path string) bool {
if len(path) > 4096 {
// path cannot be greater than Linux PATH_MAX
// this is to avoid a busy loop, that can happen
// if the caller sends path of following style
// a/a/a/a/a/a/a/a...
return true
}
path = filepath.ToSlash(strings.TrimSpace(path)) // For windows '\' must be converted to '/'
for _, p := range strings.Split(path, SlashSeparator) {
switch strings.TrimSpace(p) {