| 63 | // ----------------------------------------------------------------------- |
| 64 | |
| 65 | static bool run_script(const char * label, |
| 66 | const string & scriptPath, |
| 67 | const FileAccessPtr & fAccess, |
| 68 | CodeOfPolicies policies, |
| 69 | TextPrinter & tout) { |
| 70 | tout << "--- " << label << " ---\n"; |
| 71 | |
| 72 | ModuleGroup dummyLibGroup; |
| 73 | auto program = compileDaScript(scriptPath, fAccess, tout, |
| 74 | dummyLibGroup, policies); |
| 75 | if (program->failed()) { |
| 76 | tout << " Compilation FAILED (expected in sandbox demo):\n"; |
| 77 | int shown = 0; |
| 78 | for (auto & err : program->errors) { |
| 79 | if (shown++ >= 3) { |
| 80 | tout << " ... and " << (int(program->errors.size()) - 3) |
| 81 | << " more error(s)\n"; |
| 82 | break; |
| 83 | } |
| 84 | tout << " " << reportError(err.at, err.what, err.extra, |
| 85 | err.fixme, err.cerr); |
| 86 | } |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | Context ctx(program->getContextStackSize()); |
| 91 | if (!program->simulate(ctx, tout)) { |
| 92 | tout << " Simulation failed\n"; |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | auto fnTest = ctx.findFunction("test"); |
| 97 | if (!fnTest) { |
| 98 | tout << " Function 'test' not found\n"; |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | ctx.evalWithCatch(fnTest, nullptr); |
| 103 | if (auto ex = ctx.getException()) { |
| 104 | tout << " Exception: " << ex << "\n"; |
| 105 | return false; |
| 106 | } |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | // ----------------------------------------------------------------------- |
| 111 | // Script that uses unsafe — should be blocked by sandbox |
no test coverage detected