Panic: assignment to entry in nil map in NewRegoPolicyInterpreter (copyObject)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 58/100
Direzione di ricerca
Inizia in internal/regopolicyinterpreter/regopolicyinterpreter.go, nell’implementazione di copyObject e nel percorso NewRegoPolicyInterpreter intorno alla riga 85. Riproduci il caso di mappa vuota descritto nell’issue, quindi esegui go test -fuzz=FuzzInterpreterLogic -fuzztime=15m; il lavoro è terminato quando un input vuoto non causa più un panic per l’assegnazione a una mappa nil.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Description
Invoking NewRegoPolicyInterpreter with an empty map as initial data can panic with assignment to entry in nil map due to how the internal copyObject function handles empty input.
Steps to Reproduce
- Call
NewRegoPolicyInterpreterand passmake(map[string]interface{})(an empty map) for the data parameter. - The function panics when attempting
data["metadata"] = ...inside the constructor.
Root Cause
- In
copyObject, unmarshaling JSON into a nil map returns a nil map, not an initialized map. - Later code assumes the map is always initialized and safe to assign fields to.
Impact
- Triggers a runtime panic with valid (but empty) input.
Recommendation
- Modify
copyObjectto add check for nil or empty input:
func copyObject(data map[string]interface{}) (map[string]interface{}, error) {
// Handle nil or empty input
if data == nil {
return make(map[string]interface{}), nil
}
objJSON, err := json.Marshal(data)
if err != nil {
return nil, err
}
objCopy := make(map[string]interface{}) // Initialize before unmarshaling!
err = json.Unmarshal(objJSON, &objCopy)
if err != nil {
return nil, err
}
return objCopy, nil
}
Fuzzer Identification
- I discovered this issue while fuzzing the regopolicyinterpreter. Here's the test case:
package regopolicyinterpreter
import (
"testing"
)
func FuzzInterpreterLogic(f *testing.F) {
// Seed with a basic Rego package and a query
f.Add("package test\nallow = true", "data.test.allow")
f.Fuzz(func(t *testing.T, moduleCode string, queryStr string) {
// 1. Initialize the interpreter with fuzzed code
rpi, err := NewRegoPolicyInterpreter(moduleCode, nil)
if err != nil {
t.Skip() // Ignore invalid Rego syntax
}
// 2. Try to add a fuzzed module (AddModule returns nothing)
rpi.AddModule("fuzzed.rego", &RegoModule{
Namespace: "fuzzed",
Code: moduleCode,
})
// 3. Attempt a raw query with an empty input map
// want (string, map[string]interface{})
input := make(map[string]interface{})
_, _ = rpi.RawQuery(queryStr, input)
})
}
- Running with:
go test -fuzz=FuzzInterpreterLogic -fuzztime=15m
- Lingua principale
- Go
- Stelle
- 694
- Fork
- 304
- Merge medio
- 1g 19h
- PR unite (30g)
- 28
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/hcsshim
-
Stdin handle required to avoid conpty race condition upon WCOW container startup with terminal Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 62/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
Tutte le issue di microsoft/hcsshim
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
-
enhancement needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
kind/cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
sympozium-ai/sympozium#627 ·