SagerNet / SagerNet/sing-box

Trailing comma in json config causes ‘configure tun interface: invalid argument’

Open
#4,472 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
38.1k
Forks
4.6k
Avg merge
19d 15h
Merged PRs (30d)
1

Description

Operating system

Android

System version

Android 10 (Huawei EMUI 12)

Installation type

sing-box for Android Graphical Client

If you are using a graphical client, please provide the version of the client.

1.14.5-rc5

Version

Description

I have a minimal tun configuration that works fine (see below).

If I add a trailing comma anywhere (in the example, inside the dns server definition), sing-box fails to start:
Image

This is easily fixed using the Format button in the editor, but that is not apparent from the error message.

Also, this is a regression since previous SFA releases did support trailing commas, and should be fixed so upgrading doesn't break existing configs.

Reproduction
Working json config
{
  "dns": {
    "servers": [
      {
        "type": "local",
        "tag": "local-dns"
      }
    ],
    "final": "local-dns"
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "mtu": 1380,
      "address": [
        "172.29.254.189/30",
        "fd77:e057:ac0c:8dac:319b:b6e2:4a8b:7c00/126"
      ],
      "auto_route": true,
      "include_package": [
        "com.termux",
        "io.nekohasekai.sfa"
      ],
      "stack": "system"
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct-out"
    }
  ],
  "route": {
    "rules": [
      {
        "inbound": "tun-in",
        "ip_cidr": [
          "172.29.254.189/30",
          "fd77:e057:ac0c:8dac:319b:b6e2:4a8b:7c00/126"
        ],
        "port": 53,
        "action": "hijack-dns"
      },
      {
        "inbound": "tun-in",
        "ip_cidr": [
          "172.29.254.189/30",
          "fd77:e057:ac0c:8dac:319b:b6e2:4a8b:7c00/126"
        ],
        "action": "reject"
      }
    ],
    "final": "direct-out",
    "auto_detect_interface": true,
    "default_domain_resolver": "local-dns"
  }
}
Broken json config
{
  "dns": {
    "servers": [
      {
        "type": "local",
        "tag": "local-dns",
      }
    ],
    "final": "local-dns"
  },
  "inbounds": [
    {
      "type": "tun",
      "tag": "tun-in",
      "mtu": 1380,
      "address": [
        "172.29.254.189/30",
        "fd77:e057:ac0c:8dac:319b:b6e2:4a8b:7c00/126"
      ],
      "auto_route": true,
      "include_package": [
        "com.termux",
        "io.nekohasekai.sfa"
      ],
      "stack": "system"
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct-out"
    }
  ],
  "route": {
    "rules": [
      {
        "inbound": "tun-in",
        "ip_cidr": [
          "172.29.254.189/30",
          "fd77:e057:ac0c:8dac:319b:b6e2:4a8b:7c00/126"
        ],
        "port": 53,
        "action": "hijack-dns"
      },
      {
        "inbound": "tun-in",
        "ip_cidr": [
          "172.29.254.189/30",
          "fd77:e057:ac0c:8dac:319b:b6e2:4a8b:7c00/126"
        ],
        "action": "reject"
      }
    ],
    "final": "direct-out",
    "auto_detect_interface": true,
    "default_domain_resolver": "local-dns"
  }
}
Logs
- stderr is empty -
Supporter
Integrity requirements
  • I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
  • I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
  • I confirm that I have provided the complete configuration files and logs, rather than just providing parts I think are useful out of confidence in my own intelligence.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the working and broken JSON configurations from the report, then trace sing-box's configuration parsing entry point and existing parser tests. The change is done when a trailing comma no longer prevents the configuration from starting, with a regression test covering the minimal example.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.