Content-Length: 357072 | pFad | http://github.com/coder/coder/pull/19045/files

CF fix: fix nil pointer dereference in ReportTask by ThomasK33 · Pull Request #19045 · coder/coder · GitHub
Skip to content

fix: fix nil pointer dereference in ReportTask #19045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions coderd/mcp/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ func (s *Server) RegisterTools(client *codersdk.Client) error {
return xerrors.Errorf("failed to initialize tool dependencies: %w", err)
}

// Register all available tools
// Register all available tools, but exclude tools that require dependencies not available in the
// remote MCP context
for _, tool := range toolsdk.All {
if tool.Name == toolsdk.ToolNameReportTask {
continue
}

s.mcpServer.AddTools(mcpFromSDK(tool, toolDeps))
}

return nil
}

Expand Down
4 changes: 4 additions & 0 deletions codersdk/toolsdk/toolsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ ONLY report an "idle" or "failure" state if you have FULLY completed the task.
if len(args.Summary) > 160 {
return codersdk.Response{}, xerrors.New("summary must be less than 160 characters")
}
// Check if task reporting is available to prevent nil pointer dereference
if deps.report == nil {
return codersdk.Response{}, xerrors.New("task reporting not available. Please ensure a task reporter is configured.")
}
err := deps.report(args)
if err != nil {
return codersdk.Response{}, err
Expand Down
54 changes: 54 additions & 0 deletions codersdk/toolsdk/toolsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,57 @@ func TestMain(m *testing.M) {

os.Exit(code)
}

func TestReportTaskNilPointerDeref(t *testing.T) {
t.Parallel()

// Create deps without a task reporter (simulating remote MCP server scenario)
client, _ := coderdtest.NewWithDatabase(t, nil)
deps, err := toolsdk.NewDeps(client)
require.NoError(t, err)

// Prepare test arguments
args := toolsdk.ReportTaskArgs{
Summary: "Test task",
Link: "https://example.com",
State: string(codersdk.WorkspaceAppStatusStateWorking),
}

_, err = toolsdk.ReportTask.Handler(t.Context(), deps, args)

// We expect an error, not a panic
require.Error(t, err)
require.Contains(t, err.Error(), "task reporting not available")
}

func TestReportTaskWithReporter(t *testing.T) {
t.Parallel()

// Create deps with a task reporter
client, _ := coderdtest.NewWithDatabase(t, nil)

called := false
reporter := func(args toolsdk.ReportTaskArgs) error {
called = true
require.Equal(t, "Test task", args.Summary)
require.Equal(t, "https://example.com", args.Link)
require.Equal(t, string(codersdk.WorkspaceAppStatusStateWorking), args.State)
return nil
}

deps, err := toolsdk.NewDeps(client, toolsdk.WithTaskReporter(reporter))
require.NoError(t, err)

args := toolsdk.ReportTaskArgs{
Summary: "Test task",
Link: "https://example.com",
State: string(codersdk.WorkspaceAppStatusStateWorking),
}

result, err := toolsdk.ReportTask.Handler(t.Context(), deps, args)
require.NoError(t, err)
require.True(t, called)

// Verify response
require.Equal(t, "Thanks for reporting!", result.Message)
}
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/coder/coder/pull/19045/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy