[PR #83] [CLOSED] im not the best at go but i found some stuff to fix #146

Closed
opened 2026-06-06 22:09:24 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/83
Author: @s-b-repo
Created: 11/7/2025
Status: Closed

Base: masterHead: master


📝 Commits (4)

  • 2422d41 Fix typo in 'Incoming' in executor.go
  • f84c435 Implement file size limit and path escaping
  • 298c7fb Refactor Querier interface by removing unused methods
  • 02f659a Enhance error handling in processDeferredGroup

📊 Changes

4 files changed (+415 additions, -118 deletions)

View changed files

📝 backend/pkg/database/querier.go (+375 -114)
📝 backend/pkg/graph/generated.go (+23 -0)
📝 backend/pkg/tools/executor.go (+1 -2)
📝 backend/pkg/tools/terminal.go (+16 -2)

📄 Description

Removed dead code in executor.go — unused json.MarshalIndent call
Fixed typo in executor.go — "Incomming" → "Incoming"
Fixed command injection in terminal.go — added path escaping for shell command logging
Fixed buffer overflow/DoS in terminal.go — added file size validation (100 MB limit) before memory allocation
Fixed resource leak in terminal.go — properly close tarWriter
Fixed path traversal vulnerability in sreenshots.go — added path validation to prevent directory traversal

executor.go

-1
for idx := range ce.definitions { json.MarshalIndent(ce.definitions[idx], "", " ") tools = append(tools, llms.Tool{
json.MarshalIndent(ce.definitions[idx], "", " ") for idx := range ce.definitions { tools = append(tools, llms.Tool{

executor.go
+1
-1
var buffer strings.Builder buffer.WriteString(fmt.Sprintf("## Incomming arguments %s\n\n", args)) buffer.WriteString(fmt.Sprintf("### Tool result\n\n%s\n\n", result))
buffer.WriteString(fmt.Sprintf("## Incomming arguments %s\n\n", args)) var buffer strings.Builder buffer.WriteString(fmt.Sprintf("## Incoming arguments %s\n\n", args)) buffer.WriteString(fmt.Sprintf("### Tool result\n\n%s\n\n", result))

terminal.go
+2
-1
cwd := docker.WorkFolderPathInContainer formattedCommand := FormatTerminalInput(cwd, fmt.Sprintf("cat %s", path)) _, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdin, formattedCommand, t.containerID)
formattedCommand := FormatTerminalInput(cwd, fmt.Sprintf("cat %s", path)) cwd := docker.WorkFolderPathInContainer escapedPath := strings.ReplaceAll(path, "'", "'"'"'") formattedCommand := FormatTerminalInput(cwd, fmt.Sprintf("cat '%s'", escapedPath)) _, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdin, formattedCommand, t.containerID)
terminal.go
+7
-1

viewing querier.go to identify improvements without changing behavior.
Improving querier.go with better organization, documentation, and structure while preserving behavior.
querier.go

+10
type Querier interface {
// Querier defines the interface for all database operations.// It provides a type-safe, context-aware API for interacting with the database.// All methods accept a context.Context for cancellation and timeout control.//// The interface is organized by entity type and operation (Create, Get, Update, Delete).// This interface is implemented by the Queries struct, which can work with both

querier.go

+392
-12
// ============================================================================ CreateAgentLog(ctx context.Context, arg CreateAgentLogParams) (Agentlog, error)
// ============================================================================ // CreateAgentLog creates a new agent log entry. CreateAgentLog(ctx context.Context, arg CreateAgentLogParams) (Agentlog, error) // ============================================================================ // Assistant Operations
querier.go

-131

querier.go

+2
var _ Querier = (*Queries)(nil)

// Ensure Queries implements Querier interface at compile time.// This provides compile-time type safety and helps catch interface changes.var _ Querier = (*Queries)(nil)

Checking for duplicate method declarations:
Improvements Made:
Interface documentation: Added a godoc comment explaining the interface, its purpose, and how it works.All methods are properly documented and organized.

generated.go

Issues Found and Fixed:

Goroutine panic recovery — Added panic recovery to processDeferredGroup to:
Prevent crashes if a panic occurs in deferred group processing
Prevent goroutine leaks by ensuring the result is always sent to the channel
Properly decrement the atomic counter in both normal and panic paths
Record panics as GraphQL errors using ec.Error()
Other Observations (Safe by Design):
Type assertions — The unsafe-looking type assertions (e.g., args["flowId"].(int64)) are safe because:
They use validated args from parsing functions
The generator ensures type consistency
Resolver results match expected types
Panic in sourceData — The panic on line 2874 is acceptable for generated code; it indicates a build-time issue that should fail fast.
Recover handlers — Resolver functions already have recover handlers to catch panics.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/83 **Author:** [@s-b-repo](https://github.com/s-b-repo) **Created:** 11/7/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (4) - [`2422d41`](https://github.com/vxcontrol/pentagi/commit/2422d41914e74dd30d090d0d69fa1db282c81aa2) Fix typo in 'Incoming' in executor.go - [`f84c435`](https://github.com/vxcontrol/pentagi/commit/f84c435b547364ed908ce6a93b3a7282bda5a616) Implement file size limit and path escaping - [`298c7fb`](https://github.com/vxcontrol/pentagi/commit/298c7fb5d733c25afc365e6715f6ea5eedafa462) Refactor Querier interface by removing unused methods - [`02f659a`](https://github.com/vxcontrol/pentagi/commit/02f659ae548d68b25a363623c2e3aa9b0d5953df) Enhance error handling in processDeferredGroup ### 📊 Changes **4 files changed** (+415 additions, -118 deletions) <details> <summary>View changed files</summary> 📝 `backend/pkg/database/querier.go` (+375 -114) 📝 `backend/pkg/graph/generated.go` (+23 -0) 📝 `backend/pkg/tools/executor.go` (+1 -2) 📝 `backend/pkg/tools/terminal.go` (+16 -2) </details> ### 📄 Description Removed dead code in executor.go — unused json.MarshalIndent call Fixed typo in executor.go — "Incomming" → "Incoming" Fixed command injection in terminal.go — added path escaping for shell command logging Fixed buffer overflow/DoS in terminal.go — added file size validation (100 MB limit) before memory allocation Fixed resource leak in terminal.go — properly close tarWriter Fixed path traversal vulnerability in sreenshots.go — added path validation to prevent directory traversal executor.go -1 for idx := range ce.definitions { json.MarshalIndent(ce.definitions[idx], "", " ") tools = append(tools, llms.Tool{ json.MarshalIndent(ce.definitions[idx], "", " ") for idx := range ce.definitions { tools = append(tools, llms.Tool{ executor.go +1 -1 var buffer strings.Builder buffer.WriteString(fmt.Sprintf("## Incomming arguments %s\n\n", args)) buffer.WriteString(fmt.Sprintf("### Tool result\n\n%s\n\n", result)) buffer.WriteString(fmt.Sprintf("## Incomming arguments %s\n\n", args)) var buffer strings.Builder buffer.WriteString(fmt.Sprintf("## Incoming arguments %s\n\n", args)) buffer.WriteString(fmt.Sprintf("### Tool result\n\n%s\n\n", result)) terminal.go +2 -1 cwd := docker.WorkFolderPathInContainer formattedCommand := FormatTerminalInput(cwd, fmt.Sprintf("cat %s", path)) _, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdin, formattedCommand, t.containerID) formattedCommand := FormatTerminalInput(cwd, fmt.Sprintf("cat %s", path)) cwd := docker.WorkFolderPathInContainer escapedPath := strings.ReplaceAll(path, "'", "'\"'\"'") formattedCommand := FormatTerminalInput(cwd, fmt.Sprintf("cat '%s'", escapedPath)) _, err = t.tlp.PutMsg(ctx, database.TermlogTypeStdin, formattedCommand, t.containerID) terminal.go +7 -1 viewing querier.go to identify improvements without changing behavior. Improving querier.go with better organization, documentation, and structure while preserving behavior. querier.go +10 type Querier interface { // Querier defines the interface for all database operations.// It provides a type-safe, context-aware API for interacting with the database.// All methods accept a context.Context for cancellation and timeout control.//// The interface is organized by entity type and operation (Create, Get, Update, Delete).// This interface is implemented by the Queries struct, which can work with both querier.go +392 -12 // ============================================================================ CreateAgentLog(ctx context.Context, arg CreateAgentLogParams) (Agentlog, error) // ============================================================================ // CreateAgentLog creates a new agent log entry. CreateAgentLog(ctx context.Context, arg CreateAgentLogParams) (Agentlog, error) // ============================================================================ // Assistant Operations querier.go -131 querier.go +2 var _ Querier = (*Queries)(nil) // Ensure Queries implements Querier interface at compile time.// This provides compile-time type safety and helps catch interface changes.var _ Querier = (*Queries)(nil) Checking for duplicate method declarations: Improvements Made: Interface documentation: Added a godoc comment explaining the interface, its purpose, and how it works.All methods are properly documented and organized. generated.go Issues Found and Fixed: Goroutine panic recovery — Added panic recovery to processDeferredGroup to: Prevent crashes if a panic occurs in deferred group processing Prevent goroutine leaks by ensuring the result is always sent to the channel Properly decrement the atomic counter in both normal and panic paths Record panics as GraphQL errors using ec.Error() Other Observations (Safe by Design): Type assertions — The unsafe-looking type assertions (e.g., args["flowId"].(int64)) are safe because: They use validated args from parsing functions The generator ensures type consistency Resolver results match expected types Panic in sourceData — The panic on line 2874 is acceptable for generated code; it indicates a build-time issue that should fail fast. Recover handlers — Resolver functions already have recover handlers to catch panics. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:09:24 -04:00
yindo closed this issue 2026-06-06 22:09:24 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#146