From ec732b0b400bf37ccc88f92b0bc7b110e1b07edc Mon Sep 17 00:00:00 2001 From: WASDetchan Date: Thu, 19 Mar 2026 13:33:34 +0300 Subject: [PATCH] API: Fix potential nil pointer dereference in executeAddRules() (#5749) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/XTLS/Xray-core/issues/5748 --------- Co-authored-by: 风扇滑翔翼 --- main/commands/all/api/rules_add.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main/commands/all/api/rules_add.go b/main/commands/all/api/rules_add.go index 2e1404e6..4ff3d0b8 100644 --- a/main/commands/all/api/rules_add.go +++ b/main/commands/all/api/rules_add.go @@ -18,6 +18,8 @@ var cmdAddRules = &base.Command{ Add routing rules to Xray. Arguments: + [c2.json]... + The configs with the rules to be added. Must be in the xray config format and must have the "routing" field -s, -server The API server address. Default 127.0.0.1:8080 @@ -63,6 +65,11 @@ func executeAddRules(cmd *base.Command, args []string) { if err != nil { base.Fatalf("failed to decode %s: %s", arg, err) } + + if conf.RouterConfig == nil { + base.Fatalf("failed to add routing rule: config did not have \"routing\" field") + } + rcs = append(rcs, *conf.RouterConfig) } if len(rcs) == 0 {