Skip to content

Commit

Permalink
basic sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaaaaaaaa committed Aug 25, 2024
1 parent ba3c7e6 commit c57f385
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,9 +1351,15 @@ static jv f_output(jq_state *jq, jv input, jv filename, jv data) {
return ret_error(filename, jv_string("filename must be a string"));

const char *name_str = jv_string_value(filename);
int sandbox = 0; // TODO: --sandbox
int sandbox = 1;
{
// TODO: replace this when --sandbox is implemented
const char *disable_sandbox = getenv("JQ_DISABLE_SANDBOX");
if (disable_sandbox && *disable_sandbox)
sandbox = 0;
}
if (sandbox) {
fprintf(stderr, "jq: dry run: %s\n", name_str);
fprintf(stderr, "jq: dry run: %s (set JQ_DISABLE_SANDBOX=1)\n", name_str);
} else {
FILE *fp = fopen(name_str, "wb");
if (!fp) {
Expand Down
2 changes: 1 addition & 1 deletion tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ grep "Expected string key after ',' in object, not '\\['" $d/err > /dev/null
## Test IO

# output
cat <<EOF | (cd $d; $VALGRIND $Q $JQ -r 'to_entries[] | _experimental_output(.key;.value) | .key' >keys)
cat <<EOF | (cd $d; JQ_DISABLE_SANDBOX=1 $VALGRIND $Q $JQ -r 'to_entries[] | _experimental_output(.key;.value) | .key' >keys)
{
"a.txt": "aaa",
"b/b.json": "invalid",
Expand Down

0 comments on commit c57f385

Please sign in to comment.