mirror of
https://github.com/docker/cli.git
synced 2026-08-24 02:24:17 -05:00
cli-plugins/hooks: limit maximum number of lines / messages
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxMessages = 10
|
||||||
|
|
||||||
func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) {
|
func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) {
|
||||||
out := hookTemplate
|
out := hookTemplate
|
||||||
if strings.Contains(hookTemplate, "{{") {
|
if strings.Contains(hookTemplate, "{{") {
|
||||||
@@ -38,7 +40,10 @@ func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) {
|
|||||||
}
|
}
|
||||||
out = b.String()
|
out = b.String()
|
||||||
}
|
}
|
||||||
return strings.Split(out, "\n"), nil
|
if n := strings.Count(out, "\n"); n > maxMessages {
|
||||||
|
return nil, fmt.Errorf("hook template contains too many messages (%d): maximum is %d", n, maxMessages)
|
||||||
|
}
|
||||||
|
return strings.SplitN(out, "\n", maxMessages), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrHookTemplateParse = errors.New("failed to parse hook template")
|
var ErrHookTemplateParse = errors.New("failed to parse hook template")
|
||||||
|
|||||||
Reference in New Issue
Block a user