Skip to content

Commit add13ab

Browse files
committed
cli-plugins/hooks: limit maximum number of lines / messages
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 055a478 commit add13ab

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cli-plugins/hooks/template.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"github.com/spf13/cobra"
1414
)
1515

16+
const maxMessages = 10
17+
1618
func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) {
1719
out := hookTemplate
1820
if strings.Contains(hookTemplate, "{{") {
@@ -38,7 +40,10 @@ func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) {
3840
}
3941
out = b.String()
4042
}
41-
return strings.Split(out, "\n"), nil
43+
if n := strings.Count(out, "\n"); n > maxMessages {
44+
return nil, fmt.Errorf("hook template contains too many messages (%d): maximum is %d", n, maxMessages)
45+
}
46+
return strings.SplitN(out, "\n", maxMessages), nil
4247
}
4348

4449
var ErrHookTemplateParse = errors.New("failed to parse hook template")

0 commit comments

Comments
 (0)