Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.26k stars 3.53k forks source link

Pattern properties segfault #1801

Open toktarev opened 3 years ago

toktarev commented 3 years ago

The following code causes segfault:

TEST(SchemaValidator, Object_PatternProperties) {
    Document sd;
    sd.Parse(
        R"(
            {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ActiveInterface": {
          "type": "string",
          "default": "eth0"
        },
        "Interfaces": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.*$": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "Ip": {
                  "type": "string"
                },
                "Netmask": {
                  "type": "string"
                },
                "Gateway": {
                  "type": "string"
                },
                "Dhcp": {
                  "type": "boolean",
                  "default": true
                }
              }
            }
          }
        },
        "DNS1": {
          "type": "string"
        },
        "DNS2": {
          "type": "string"
        },
        "NAT": {
          "enum": [
            "no",
            "router",
            "stun"
          ],
          "default": "no"
        },
        "Address": {
          "type": "string"
        },
        "Port": {
          "type": "integer",
          "default": 3478
        }
      }
    }
        )");
    SchemaDocument s(sd);

    std::string str = R"({
                "ActiveInterface": "",
                "Address": "192.168.0.1",
                "DNS1": "",
                "DNS2": "",
                "Interfaces": {
                    "eth3": {
                        "Dhcp": "true",
                        "Gateway": "10.0.2.2",
                        "Ip": "10.0.2.15",
                        "Netmask": "255.255.255.0",
                        "autoneg": "-",
                        "duplex": "-",
                        "fullSpeeds": "",
                        "halfSpeeds": "",
                        "speed": "-"
                    },
                    "eth4": {
                        "Dhcp": "true",
                        "Gateway": "",
                        "Ip": "192.168.1.4",
                        "Netmask": "255.255.255.0",
                        "autoneg": "-",
                        "duplex": "-",
                        "fullSpeeds": "",
                        "halfSpeeds": "",
                        "speed": "-"
                    }
                },
                "NAT": "no",
                "Port": "3478"
    })";

    VALIDATE(s, str, true);
}
toktarev commented 3 years ago

Version: 1.1.0

miloyip commented 3 years ago

I cannot reproduce this in the lastest master on MacOS and Windows.

toktarev commented 3 years ago

Yes, I mentioned about version: Version: 1.1.0.

I don't see other latest releases