Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions pkg/workflow/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,14 +1480,6 @@ func (c *Compiler) applyDefaultTools(tools map[string]any, safeOutputs *SafeOutp
} else if bashArray, ok := bashTool.([]any); ok {
// bash is an array - merge default commands with custom commands
if len(bashArray) > 0 {
// Security: Guard against allocation size overflow (CWE-190)
// Ensure the combined size doesn't exceed a reasonable limit
const maxBashCommands = 10000 // Reasonable limit for bash commands
if len(bashArray) > maxBashCommands {
// Silently truncate to prevent overflow while maintaining functionality
bashArray = bashArray[:maxBashCommands]
}

// Create a set to track existing commands to avoid duplicates
existingCommands := make(map[string]bool)
for _, cmd := range bashArray {
Expand All @@ -1496,18 +1488,8 @@ func (c *Compiler) applyDefaultTools(tools map[string]any, safeOutputs *SafeOutp
}
}

// Start with default commands
// Check for overflow: ensure sum won't exceed int max
defaultLen := len(constants.DefaultBashTools)
arrayLen := len(bashArray)
capacity := defaultLen + arrayLen

// Additional safety: verify the capacity is reasonable
if capacity < 0 || capacity > maxBashCommands {
capacity = maxBashCommands
}

mergedCommands := make([]any, 0, capacity)
// Start with default commands (append handles capacity automatically)
var mergedCommands []any
for _, cmd := range constants.DefaultBashTools {
if !existingCommands[cmd] {
mergedCommands = append(mergedCommands, cmd)
Expand Down