cli-plugins/hooks: max-message enforcement is off by one

未关闭 适合新手
#7,005 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
go
领域
cli

调研方向

从 cli-plugins/hooks/template.go 的第 43 行和第 46 行开始,使用 issue 中的 11 行复现代码检查 hooks.ParseTemplate()。添加一个回归测试,表明 10 个换行符会被拒绝,而处于 10 条消息限制以内的输出仍然有效;完成的标准是没有额外的行被合并到最终消息中。

由索引模型根据 Issue 内容生成。

描述

Description

cli-plugins/hooks.ParseTemplate() currently enforces maxMessages = 10 by counting newline characters and rejecting only when strings.Count(out, "\n") > maxMessages, then returning strings.SplitN(out, "\n", maxMessages).

That makes the limit off by one:

  • a template that renders to 10 newline characters actually contains 11 messages
  • that output is currently accepted instead of rejected
  • SplitN(..., 10) then merges the extra line into the last returned element, so the final "message" can still contain an embedded newline

This means the "maximum 10 messages" guard can be bypassed by one extra rendered line.

Reproduce
  1. Use the current master branch.
  2. Call hooks.ParseTemplate() with output that contains 11 lines, for example:
strings.Repeat("line\n", 10) + "line"
  1. Observe that no error is returned.
  2. Observe that the returned slice has length 10, with the last element containing an embedded newline.

The relevant logic is currently in:

  • cli-plugins/hooks/template.go:43
  • cli-plugins/hooks/template.go:46
Expected behavior

A template that renders to more than 10 messages should be rejected, including the 11-line / 10-newline case.

In other words, the limit should be enforced on the number of returned messages, not just on the number of newline separators.

docker version

N/A for runtime environment. This is a source-level issue in the current master branch checkout.

Observed in local checkout at 9f16882de4.

docker info

N/A for runtime environment. This issue is in template parsing logic and does not depend on daemon configuration.

Additional Info

This looks like it was introduced by b7ab63387a (cli-plugins/hooks: limit maximum number of lines / messages).

I’m happy to send a fix with a regression test if this behavior matches the intended bug report.

主要语言
Go
星标
6.1k
派生
2.2k
平均合并
1 天 15 小时
30 天内合并 PR
43

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

docker/cli 的其他 Issue

查看 docker/cli 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。