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

Ouverte Adaptée aux débutants
#14,983 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #15005 par @draarivpatel-ui — fermée sans fusion

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
82/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
go
Domaine
cli

Piste de recherche

La stack trace pointe vers pkg/cmd/api/fields.go, en particulier addParamsSlice à la ligne 143 et parseFields. Commencez par lire ces fonctions et les tests existants pour l’analyse des champs -F. Reproduisez le problème avec les deux options gh api user de l’issue ; le travail est terminé lorsque la commande construit le corps JSON attendu sans provoquer de panic.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
Langage dominant
Go
Étoiles
47.4k
Forks
9.5k
Merge moyen
18 h 34 min
PR mergées (30 j)
70

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de cli/cli

Toutes les issues de cli/cli

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.