mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-27 21:14:46 +03:00
fix(inbounds): refuse a null settings payload instead of panicking
An inbound save whose settings is the JSON value null reached keepStoredClients, where null decodes into a nil map without an error. Putting the stored client list back into that map panicked inside the traffic writer, so the caller got "traffic writer panic: assignment to entry in nil map" and the panel logged a stack trace. A null payload is now left as it is, and the client validation that runs next refuses it with the same "inbound settings is empty" every other empty settings value gets.
This commit is contained in:
@@ -145,7 +145,8 @@ func mergeClientLists(base, ours, current []any) []any {
|
||||
// payload: clients change through the client endpoints, never this form.
|
||||
func keepStoredClients(payload, stored string) string {
|
||||
var payloadM, storedM map[string]any
|
||||
if json.Unmarshal([]byte(payload), &payloadM) != nil || json.Unmarshal([]byte(stored), &storedM) != nil {
|
||||
// A JSON null decodes into a nil map without an error; client validation refuses it next.
|
||||
if json.Unmarshal([]byte(payload), &payloadM) != nil || json.Unmarshal([]byte(stored), &storedM) != nil || payloadM == nil {
|
||||
return payload
|
||||
}
|
||||
storedClients, has := storedM["clients"]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -168,3 +169,20 @@ func TestInboundFormSaveKeepsEnableToggledWhileOpen(t *testing.T) {
|
||||
t.Fatalf("after save: enable=%v remark=%q, want disabled and edited", saved.Enable, saved.Remark)
|
||||
}
|
||||
}
|
||||
|
||||
// A null settings payload is not an object the stored clients can be put back
|
||||
// into; the save must refuse it like any other empty settings.
|
||||
func TestInboundFormSaveRefusesNullSettings(t *testing.T) {
|
||||
setupBulkDB(t)
|
||||
ib := seedRenewableNeighbour(t, 23209, nil)
|
||||
form := *ib
|
||||
form.Settings = "null"
|
||||
|
||||
_, _, err := (&InboundService{}).UpdateInbound(&form)
|
||||
if err == nil || strings.TrimSpace(err.Error()) != "inbound settings is empty" {
|
||||
t.Fatalf("UpdateInbound err = %v, want %q", err, "inbound settings is empty")
|
||||
}
|
||||
if _, ok := settingsClient(t, ib.Id, "y@stale"); !ok {
|
||||
t.Fatal("the refused save dropped a stored client")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user