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

Offen Anfängerfreundlich
#14,983 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

  • #15005 von @draarivpatel-ui — ohne Merge geschlossen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
82/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
go
Bereich
cli

Rechercherichtung

Der Stacktrace verweist auf pkg/cmd/api/fields.go, insbesondere auf addParamsSlice in Zeile 143 und parseFields. Lies zunächst diese Funktionen und die vorhandenen Tests zum Parsen von -F-Feldern. Reproduziere den Fehler mit den beiden gh api user-Flags aus dem Issue; die Aufgabe ist abgeschlossen, wenn der Befehl den erwarteten JSON-Body erstellt, ohne in einen Panic zu laufen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug gh-api priority-3
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 https://github.com/cli/cli/pull/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
Vorherrschende Sprache
Go
Sterne
47.4k
Forks
9.5k
Ø Merge
18 Std. 34 Min.
Gemergte PRs (30 T.)
70

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus cli/cli

Alle Issues in cli/cli

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.