Skip to content
Merged
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
13 changes: 12 additions & 1 deletion tools/specification_parser/lint_json_output.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from os.path import curdir, abspath, join, splitext
from os.path import curdir, abspath, realpath, join, splitext, commonpath
from os import walk
import json
import sys


def _safe_path(f):
# resolve symlinks and reject paths that escape the current working directory
base = realpath(curdir)
target = realpath(f)
if commonpath([base, target]) != base:
print(f"Refusing to read path outside {base}: {f}", file=sys.stderr)
sys.exit(1)
return target


def main(f):
f = _safe_path(f)
errors = 0
with open(f) as jsonfile:
spec = json.load(jsonfile)
Expand Down
Loading