Add basic validation for max/min file count and scan values

This commit is contained in:
Seednode 2023-09-26 04:03:52 -05:00
parent 935021e464
commit f7376e89b9
2 changed files with 19 additions and 5 deletions

View File

@ -16,9 +16,11 @@ import (
)
var (
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
ErrInvalidScanCount = errors.New("scan count must be a positive integer")
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
ErrInvalidFileCountRange = errors.New("maximum file count must be greater than or equal to minimum file count")
ErrInvalidFileCountValue = errors.New("file count value must be an integer between 1 and 2147483647 inclusive")
ErrInvalidPort = errors.New("listen port must be an integer between 1 and 65535 inclusive")
ErrInvalidScanCount = errors.New("scan count must be a positive integer")
ErrNoMediaFound = errors.New("no supported media formats found which match all criteria")
)
func newErrorPage(title, body string) string {

View File

@ -11,7 +11,7 @@ import (
)
const (
ReleaseVersion string = "0.93.1"
ReleaseVersion string = "0.93.2"
)
var (
@ -55,6 +55,18 @@ var (
return ErrInvalidScanCount
}
if MaxFileCount > 1<<31-1 || MaxFileCount < 1 {
return ErrInvalidFileCountValue
}
if MinFileCount > 1<<31-1 || MinFileCount < 1 {
return ErrInvalidFileCountValue
}
if MinFileCount > MaxFileCount {
return ErrInvalidFileCountRange
}
if Port < 1 || Port > 65535 {
return ErrInvalidPort
}
@ -96,7 +108,7 @@ func init() {
rootCmd.Flags().BoolVarP(&Info, "info", "i", false, "expose informational endpoints")
rootCmd.Flags().IntVar(&MaxDirScans, "max-directory-scans", 32, "number of directories to scan at once")
rootCmd.Flags().IntVar(&MaxFileScans, "max-file-scans", 256, "number of files to scan at once")
rootCmd.Flags().IntVar(&MaxFileCount, "max-file-count", 1<<32-1, "skip directories with file counts above this value")
rootCmd.Flags().IntVar(&MaxFileCount, "max-file-count", 1<<31-1, "skip directories with file counts above this value")
rootCmd.Flags().IntVar(&MinFileCount, "min-file-count", 1, "skip directories with file counts below this value")
rootCmd.Flags().IntVar(&PageLength, "page-length", 0, "pagination length for info pages")
rootCmd.Flags().IntVarP(&Port, "port", "p", 8080, "port to listen on")