Skip to content

Commit

Permalink
bugtool: fix IP route debug gathering commands
Browse files Browse the repository at this point in the history
Commit 8bcc4e5 ("bugtool: avoid allocation on conversion of
execCommand result to string") broke the `ip route show` commands
because the change from `[]byte` to `string` causes the `%v` formatting
verb to emit the raw byte slice, not the string. Fix this by using the
`%s` formatting verb to make sure the argument gets interpreted as a
string.

Also fix another instance in `writeCmdToFile` where `fmt.Fprint` is now
invoked with a byte slice.

Grepping for `%v` in bugtool sources and manually inspecting all changes
from commit 8bcc4e5 showed no other instances where a byte slice
could potentially end up being formatted in a wrong way.

Fixes: 8bcc4e5 ("bugtool: avoid allocation on conversion of execCommand result to string")

Signed-off-by: Tobias Klauser <tobias@cilium.io>
  • Loading branch information
tklauser authored and borkmann committed Nov 30, 2021
1 parent 7376df3 commit e38e3c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bugtool/cmd/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ func routeCommands() []string {
routes, _ := execCommand("ip route show table all | grep -E --only-matching 'table [0-9]+'")

for _, r := range bytes.Split(bytes.TrimSuffix(routes, []byte("\n")), []byte("\n")) {
routeTablev4 := fmt.Sprintf("ip -4 route show %v", r)
routeTablev6 := fmt.Sprintf("ip -6 route show %v", r)
routeTablev4 := fmt.Sprintf("ip -4 route show %s", r)
routeTablev6 := fmt.Sprintf("ip -6 route show %s", r)
commands = append(commands, routeTablev4, routeTablev6)
}
return commands
Expand Down
2 changes: 1 addition & 1 deletion bugtool/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func writeCmdToFile(cmdDir, prompt string, k8sPods []string, enableMarkdown bool
// produced might have useful information
if bytes.Contains(output, []byte("```")) || !enableMarkdown {
// Already contains Markdown, print as is.
fmt.Fprint(f, output)
fmt.Fprint(f, string(output))
} else if enableMarkdown && len(output) > 0 {
// Write prompt as header and the output as body, and/or error but delete empty output.
fmt.Fprint(f, fmt.Sprintf("# %s\n\n```\n%s\n```\n", prompt, output))
Expand Down

0 comments on commit e38e3c4

Please sign in to comment.