Skip to content

Nil pointer dereference when trying to use the adrules api with empty config #5748

@WASDetchan

Description

@WASDetchan

完整性要求

  • 我读完了 issue 模板中的所有注释,确保填写符合要求。
  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我提供了完整的配置文件和日志,而不是出于自己的判断只给出截取的部分。
  • 我搜索了 issues, 没有发现已提出的类似问题。
  • 问题在 Release 最新的版本上可以成功复现

描述

When using a config file which is a valid xray config file, but has no "routing" field (see Reproduction), a panic caused by nil pointer dereference occurs.

$ ./xray api adrules -s=127.0.0.1:8080 empty_routing.json
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11330dc]

goroutine 1 [running]:
github.com/xtls/xray-core/main/commands/all/api.executeAddRules(0x2271c80, {0x2557ff0ca030, 0x2, 0x2})
	github.com/xtls/xray-core/main/commands/all/api/rules_add.go:66 +0x3dc
github.com/xtls/xray-core/main/commands/base.Execute()
	github.com/xtls/xray-core/main/commands/base/execute.go:64 +0x59f
main.main()
	github.com/xtls/xray-core/main/main.go:22 +0x1a5

Expected behavior: quit with an error message

重现方式

  1. Build xray-core from the latest commit ( 0bffea3 )
$ go version 
go version go1.26.0-X:nodwarf5 linux/amd64
$ ./xray --version
Xray 26.2.6 (Xray, Penetrates Everything.) Custom (go1.26.0-X:nodwarf5 linux/amd64)
A unified platform for anti-censorship.
  1. Launch xray with a minimal config with api enabled (see Server Configuration). Server is only needed so api proceeds to use the route config.
$ ./xray run -c config.json
Xray 26.2.6 (Xray, Penetrates Everything.) Custom (go1.26.0-X:nodwarf5 linux/amd64)
  1. Create an empty empty_routing.json:
{
    
}
  1. Attempt to apply it using the api:
$ ./xray api adrules -s=127.0.0.1:8080 empty_routing.json
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11330dc]

goroutine 1 [running]:
github.com/xtls/xray-core/main/commands/all/api.executeAddRules(0x2271c80, {0x2557ff0ca030, 0x2, 0x2})
	github.com/xtls/xray-core/main/commands/all/api/rules_add.go:66 +0x3dc
github.com/xtls/xray-core/main/commands/base.Execute()
	github.com/xtls/xray-core/main/commands/base/execute.go:64 +0x59f
main.main()
	github.com/xtls/xray-core/main/main.go:22 +0x1a5

客户端配置

There's no client

服务端配置

Details

{
  "api": {
    "tag": "api",
    "listen": "127.0.0.1:8080",
    "services": [
      "StatsService",
      "RoutingService"
    ]
  },
  "log": {
    "loglevel": "debug"
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10085,
      "protocol": "dokodemo-door",
      "settings": {
        "address": "127.0.0.1"
      },
      "tag": "api"
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "direct"
    }
  ]
}

客户端日志

Details

$ ./xray api adrules -s=127.0.0.1:8080 empty_routing.json
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11330dc]

goroutine 1 [running]:
github.com/xtls/xray-core/main/commands/all/api.executeAddRules(0x2271c80, {0x2557ff0ca030, 0x2, 0x2})
github.com/xtls/xray-core/main/commands/all/api/rules_add.go:66 +0x3dc
github.com/xtls/xray-core/main/commands/base.Execute()
github.com/xtls/xray-core/main/commands/base/execute.go:64 +0x59f
main.main()
github.com/xtls/xray-core/main/main.go:22 +0x1a5

服务端日志

Details

$ ./xray run -c config.json
Xray 26.2.6 (Xray, Penetrates Everything.) Custom (go1.26.0-X:nodwarf5 linux/amd64)
A unified platform for anti-censorship.
2026/03/02 13:16:05.279143 [Info] infra/conf/serial: Reading config: &{Name:config.json Format:json}
2026/03/02 13:16:05.281161 [Debug] app/log: Logger started
2026/03/02 13:16:05.281378 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:10085
2026/03/02 13:16:05.281727 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:10085
2026/03/02 13:16:05.281821 [Info] app/commander: API server listening on 127.0.0.1:8080
2026/03/02 13:16:05.281836 [Warning] core: Xray 26.2.6 started

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions