v2fly / v2ray-core

A platform for building proxies to bypass network restrictions.
https://v2fly.org
MIT License
28.24k stars 4.51k forks source link

A bug encountered when loading configuration text via STDIN #3028

Open Hylaea opened 1 month ago

Hylaea commented 1 month ago

What version of V2Ray are you using?

5.16.1

What's your scenario of using V2Ray?

Socks and VMess proxy, and Intranet penetration

What problems have you encountered?

A bug encountered when loading configuration text via STDIN. panic: runtime error: invalid memory address or nil pointer dereference

Windows10 Startup script: type vpoint_vmess_freedom.json | v2ray.exe run Centos7 Startup script: cat vpoint_vmess_freedom.json | ./v2ray run

Note: Delete config.json first, otherwise will load configuration from config. json instead of STDIN.

What's your expectation?

The program is able to read configuration text correctly from STDIN, because these configuration text are generated dynamically and do not want to be written to the hard disk.

Please attach your configuration here

Server configuration: _The configuration comes from vpoint_vmessfreedom.json

{
  "inbounds": [{
    "port": 10086,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "23ad6b10-8d1a-40f7-8ad0-e3e35cd38297",
          "level": 1,
          "alterId": 64
        }
      ]
    }
  }],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      }
    ]
  }
}

Client configuration: Same as the server configuration.

Please attach error logs here

Server error log: No log file because the program failed to start.

Client error log: No log file because the program failed to start.

Please attach access log here

No log file because the program failed to start.

Other configurations (such as Nginx) and logs here

None

If V2Ray cannot start up, please attach output from --test command

V2Ray 5.16.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.22.2 linux/amd64)
A unified platform for anti-censorship.
2024/05/23 10:42:06 Using config from STDIN
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xd8 pc=0x121bc7e]

goroutine 1 [running]:
github.com/v2fly/v2ray-core/v5/infra/conf/v2jsonpb.(*V2JsonProtobufFollowerFieldDescriptor).Number(0x0?)
    <autogenerated>:1 +0x1e
google.golang.org/protobuf/encoding/protojson.decoder.unmarshalMessage({0xc0004f95e0, {{}, 0x1, 0x0, {0x17eef88, 0xc0004c9f10}, 0x270f}}, {0x1802598, 0xc0004c9f20}, 0x0)
    google.golang.org/protobuf@v1.34.0/encoding/protojson/decode.go:213 +0x870
google.golang.org/protobuf/encoding/protojson.UnmarshalOptions.unmarshal({{}, 0x1, 0x0, {0x17eef88, 0xc0004c9f10}, 0x2710}, {0xc00021e480, 0x219, 0x219}, {0x17df920, ...})
    google.golang.org/protobuf@v1.34.0/encoding/protojson/decode.go:80 +0x1bc
google.golang.org/protobuf/encoding/protojson.UnmarshalOptions.Unmarshal(...)
    google.golang.org/protobuf@v1.34.0/encoding/protojson/decode.go:63
github.com/v2fly/v2ray-core/v5/infra/conf/v2jsonpb.loadV2JsonPb({0xc00021e480, 0x219, 0x219})
    github.com/v2fly/v2ray-core/v5/infra/conf/v2jsonpb/v2jsonpb.go:21 +0x196
github.com/v2fly/v2ray-core/v5/infra/conf/v2jsonpb.init.0.func1({0x12e5ac0?, 0xc0000b1188?})
    github.com/v2fly/v2ray-core/v5/infra/conf/v2jsonpb/v2jsonpb.go:60 +0xb8
github.com/v2fly/v2ray-core/v5.loadSingleConfigByTryingAllLoaders({0x12e5ac0, 0xc0000b1188})
    github.com/v2fly/v2ray-core/v5/config.go:174 +0xa2
github.com/v2fly/v2ray-core/v5.loadSingleConfigAutoFormat({0x15864c0?, 0xc000066010?})
    github.com/v2fly/v2ray-core/v5/config.go:148 +0x14c
github.com/v2fly/v2ray-core/v5.LoadConfig({0x15a1f6a, 0x4}, {0x131e900, 0x28e2420})
    github.com/v2fly/v2ray-core/v5/config.go:110 +0x125
github.com/v2fly/v2ray-core/v5/main/commands.startV2Ray()
    github.com/v2fly/v2ray-core/v5/main/commands/run.go:194 +0x4c
github.com/v2fly/v2ray-core/v5/main/commands.executeTest(0x233ca60, {0xc00003e050, 0x0, 0x0})
    github.com/v2fly/v2ray-core/v5/main/commands/test.go:54 +0x8a
github.com/v2fly/v2ray-core/v5/main/commands/base.Execute()
    github.com/v2fly/v2ray-core/v5/main/commands/base/execute.go:67 +0x63d
main.main()
    github.com/v2fly/v2ray-core/v5/main/main.go:16 +0x285

If V2Ray service is abnormal, please attach journal log here

Not a service

ghosx commented 1 week ago

Try use xargs

v2ray-core git:(346ca66c) ✗ cat vpoint_vmess_freedom.json|xargs ./v2ray run
V2Ray 5.16.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.21.7 linux/amd64)
A unified platform for anti-censorship.
2024/06/20 21:09:24 Using config from STDIN
2024/06/20 21:09:24 [Warning] V2Ray 5.16.1 started