Skip to content

gh api panics with a nil pointer dereference when a magic field value of null is used in a nested array #14983

Open

Description

@daniellockyer

Describe the bug

gh api crashes with a nil pointer dereference when a magic field (-F) with the literal value null is used on a nested array key, and a second field targets the same nested array element.

The crash happens while parsing the command line flags, before any HTTP request is made, so it is reproducible without network access.

I have a fix to PR if the issue can be labelled appropriately 🙂

Affected version

$ gh version
gh version 2.103.3-71-g736c68f67 (2026-11-07)
https://github.com/cli/cli/releases/latest

This is a build of trunk. The offending code has not changed since it was introduced in #8762, so every release from v2.48.0 onward is affected, including the latest release v2.103.3.

Steps to reproduce the behavior

gh api user -F 'a[][b]=null' -F 'a[][b]=x'

Expected vs actual behavior

Expected: the request body should be built as {"a":[{"b":null},{"b":"x"}]} and the request sent.

Actual: gh panics and exits with status 2.

Logs

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xd999cb]

goroutine 1 [running]:
github.com/cli/cli/v2/pkg/cmd/api.addParamsSlice(0x9de41564390, {0x7ffcae24ee19, 0x1}, {0x7ffcae24ee1d, 0x1})
	github.com/cli/cli/v2/pkg/cmd/api/fields.go:143 +0x14b
github.com/cli/cli/v2/pkg/cmd/api.parseFields.func1({0x7ffcae24ee19, 0x8}, 0x1)
	github.com/cli/cli/v2/pkg/cmd/api/fields.go:75 +0x7b1
github.com/cli/cli/v2/pkg/cmd/api.parseFields(0x9de4137c140)
	github.com/cli/cli/v2/pkg/cmd/api/fields.go:115 +0xee
github.com/cli/cli/v2/pkg/cmd/api.apiRun(0x9de4137c140)
	github.com/cli/cli/v2/pkg/cmd/api/api.go:314 +0x33
github.com/cli/cli/v2/pkg/cmd/api.NewCmdApi.func2(0x9de41364008, {0x9de413e0a50?, 0x0?, 0x0?})
	github.com/cli/cli/v2/pkg/cmd/api/api.go:290 +0x2c9
github.com/cli/cli/v2/pkg/cmdutil.RecordTelemetry.func2(0x9de41364008, {0x9de41364008, 0x1?, 0x5?})
	github.com/cli/cli/v2/pkg/cmdutil/telemetry.go:40 +0x32
github.com/spf13/cobra.(*Command).execute(0x9de41364008, {0x9de413e0a00, 0x5, 0x5})
	github.com/spf13/[email protected]/command.go:1015 +0xb3
github.com/spf13/cobra.(*Command).ExecuteC(0x9de41047b08)
	github.com/spf13/[email protected]/command.go:1148 +0x450
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
	github.com/spf13/[email protected]/command.go:1080
github.com/cli/cli/v2/internal/ghcmd.Main()
	github.com/cli/cli/v2/internal/ghcmd/cmd.go:187 +0x1065
main.main()
	github.com/cli/cli/v2/cmd/gh/main.go:10 +0x13
exit status 2

Activity

  1. added
    needs-triage
    on Nov 7, 2026
  2. cli-triage commented on Nov 7, 2026

    @cli-triage

    Reproducible on 2.103.3.

    Using test data, the command crashes while parsing fields, before any request is sent:

    $ gh api user -F 'a[][b]=null' -F 'a[][b]=x'
    panic: runtime error: invalid memory address or nil pointer dereference

    Exit status: 2.

    The latest release and current source build also crash with the same stack location. The null value becomes nil, and the next nested field causes the parser to inspect its type without first checking for nil. This looks ready for a focused parser fix and a regression test covering nested array fields.

    Supporting reports

    Generated by issue triage.

  3. added
    bug
    priority-3
    gh-api
    on Nov 9, 2026
  4. removed
    needs-triage
    on Nov 9, 2026
  5. added 2 commits that reference this issue on Nov 10, 2026
    0a35cbe
    c4151a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-apipriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions