mirror of
https://github.com/minio/minio.git
synced 2025-04-10 14:37:53 -04:00
parent
b37a02cddf
commit
ab77b216d1
31
cmd/posix.go
31
cmd/posix.go
@ -108,20 +108,31 @@ func checkPathLength(pathName string) error {
|
|||||||
return errFileNameTooLong
|
return errFileNameTooLong
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
// Disallow more than 1024 characters on windows, there
|
||||||
// Convert any '\' to '/'.
|
// are no known name_max limits on Windows.
|
||||||
pathName = filepath.ToSlash(pathName)
|
if runtime.GOOS == "windows" && len(pathName) > 1024 {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check each path segment length is > 255
|
// On Unix we reject paths if they are just '.', '..' or '/'
|
||||||
for len(pathName) > 0 && pathName != "." && pathName != SlashSeparator {
|
if pathName == "." || pathName == ".." || pathName == slashSeparator {
|
||||||
dir, file := slashpath.Dir(pathName), slashpath.Base(pathName)
|
return errFileAccessDenied
|
||||||
|
}
|
||||||
|
|
||||||
if len(file) > 255 {
|
// Check each path segment length is > 255 on all Unix
|
||||||
return errFileNameTooLong
|
// platforms, look for this value as NAME_MAX in
|
||||||
|
// /usr/include/linux/limits.h
|
||||||
|
var count int64
|
||||||
|
for _, p := range pathName {
|
||||||
|
switch p {
|
||||||
|
case '/':
|
||||||
|
count = 0 // Reset
|
||||||
|
default:
|
||||||
|
count++
|
||||||
|
if count > 255 {
|
||||||
|
return errFileNameTooLong
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pathName = dir
|
|
||||||
} // Success.
|
} // Success.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* MinIO Cloud Storage, (C) 2016, 2017 MinIO, Inc.
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -32,6 +32,33 @@ import (
|
|||||||
"github.com/minio/minio/pkg/disk"
|
"github.com/minio/minio/pkg/disk"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestCheckPathLength(t *testing.T) {
|
||||||
|
// Check path length restrictions are not same on windows/darwin
|
||||||
|
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
path string
|
||||||
|
expectedErr error
|
||||||
|
}{
|
||||||
|
{".", errFileAccessDenied},
|
||||||
|
{"/", errFileAccessDenied},
|
||||||
|
{"..", errFileAccessDenied},
|
||||||
|
{"data/G_792/srv-tse/c/users/denis/documents/gestion!20locative/heritier/propri!E9taire/20190101_a2.03!20-!20m.!20heritier!20re!B4mi!20-!20proce!60s-verbal!20de!20livraison!20et!20de!20remise!20des!20cle!B4s!20acque!B4reurs!20-!204-!20livraison!20-!20lp!20promotion!20toulouse!20-!20encre!20et!20plume!20-!205!20de!B4c.!202019!20a!60!2012-49.pdf.ecc", errFileNameTooLong},
|
||||||
|
{"data/G_792/srv-tse/c/users/denis/documents/gestionlocative.txt", nil},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
gotErr := checkPathLength(testCase.path)
|
||||||
|
t.Run("", func(t *testing.T) {
|
||||||
|
if gotErr != testCase.expectedErr {
|
||||||
|
t.Errorf("Expected %s, got %s", testCase.expectedErr, gotErr)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tests validate volume name.
|
// Tests validate volume name.
|
||||||
func TestIsValidVolname(t *testing.T) {
|
func TestIsValidVolname(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user