Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segmentation fault when resolving a schema with a missing open brace #196

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_jsonschema_test_unix(validate/fail_relative_external_ref_missing)
add_jsonschema_test_unix(validate/fail_resolve_enoent)
add_jsonschema_test_unix(validate/fail_resolve_directory_with_invalid_json)
add_jsonschema_test_unix(validate/fail_resolve_invalid_json)
add_jsonschema_test_unix(validate/fail_resolve_missing_open_brace)
add_jsonschema_test_unix(validate/fail_schema_directory)
add_jsonschema_test_unix(validate/fail_schema_enoent)
add_jsonschema_test_unix(validate/fail_schema_invalid_json)
Expand Down
39 changes: 39 additions & 0 deletions test/validate/fail_resolve_missing_open_brace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "string"
}
EOF

cat << 'EOF' > "$TMP/instance.json"
"foo"
EOF

cat << 'EOF' > "$TMP/invalid.json"

"$schema": "http://json-schema.org/draft-04/schema#",
"$id": "https://example.com",
"type": "string"
}
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.json" \
--resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
error: Failed to parse the JSON document at line 2 and column 3
$(realpath "$TMP")/invalid.json
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
Loading