Skip to content

Commit b8df20c

Browse files
committed
Fix segmentation fault when resolving a schema with a missing open brace
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 13d7bf1 commit b8df20c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ add_jsonschema_test_unix(validate/fail_relative_external_ref_missing)
3737
add_jsonschema_test_unix(validate/fail_resolve_enoent)
3838
add_jsonschema_test_unix(validate/fail_resolve_directory_with_invalid_json)
3939
add_jsonschema_test_unix(validate/fail_resolve_invalid_json)
40+
add_jsonschema_test_unix(validate/fail_resolve_missing_open_brace)
4041
add_jsonschema_test_unix(validate/fail_schema_directory)
4142
add_jsonschema_test_unix(validate/fail_schema_enoent)
4243
add_jsonschema_test_unix(validate/fail_schema_invalid_json)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
TMP="$(mktemp -d)"
7+
clean() { rm -rf "$TMP"; }
8+
trap clean EXIT
9+
10+
cat << 'EOF' > "$TMP/schema.json"
11+
{
12+
"$schema": "http://json-schema.org/draft-04/schema#",
13+
"type": "string"
14+
}
15+
EOF
16+
17+
cat << 'EOF' > "$TMP/instance.json"
18+
"foo"
19+
EOF
20+
21+
cat << 'EOF' > "$TMP/invalid.json"
22+
23+
"$schema": "http://json-schema.org/draft-04/schema#",
24+
"$id": "https://example.com",
25+
"type": "string"
26+
}
27+
EOF
28+
29+
"$1" validate "$TMP/schema.json" "$TMP/instance.json" \
30+
--resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \
31+
&& CODE="$?" || CODE="$?"
32+
test "$CODE" = "1" || exit 1
33+
34+
cat << EOF > "$TMP/expected.txt"
35+
error: Failed to parse the JSON document at line 2 and column 3
36+
$(realpath "$TMP")/invalid.json
37+
EOF
38+
39+
diff "$TMP/stderr.txt" "$TMP/expected.txt"

0 commit comments

Comments
 (0)