added ability to disable #file_contents
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 18 Jul 2021 19:46:19 +0000 (14:46 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 18 Jul 2021 19:46:19 +0000 (14:46 -0500)
bin/onyx
include/onyxastnodes.h
src/onyx.c
src/onyxchecker.c

index fd417834abaebd71bc29bed92520335d68a2a2d1..9d744b0845fc5d93e8e20fb7b8f56d5deb4bf0ef 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 5060d1eea394f4b72ee267323fc4b947c9373cea..790b10e284a35950cd9eee73899bd41a697af1a8 100644 (file)
@@ -1155,6 +1155,7 @@ struct CompileOptions {
     b32 print_static_if_results : 1;
     b32 print_notes             : 1;
     b32 no_colors               : 1;
+    b32 no_file_contents        : 1;
     
     b32 use_post_mvp_features : 1;
 
index e5aea9c63abc5d79df1afa6f5cd448b25ab7fe53..ec2d87fa758475c38ad16eb2b05e1cc35d61c62b 100644 (file)
@@ -43,13 +43,14 @@ static const char* docstring = "Onyx compiler version " VERSION "\n"
     "\t           -VV          Very verbose output\n"
     "\t           -VVV         Very very verbose output (to be used by compiler developers)\n"
     "\t--use-post-mvp-features Enables post MVP WASM features such as memory.copy and memory.fill\n"
-    "\t--doc <doc_file>"
+    "\t--doc <doc_file>\n"
     "\n"
     "Developer flags:\n"
     "\t--print-function-mappings Prints a mapping from WASM function index to source location.\n"
     "\t--print-static-if-results Prints the conditional result of each #if statement. Useful for debugging.\n"
     "\t--print-notes             Prints the location of notes throughout the loaded code.\n"
     "\t--no-colors               Disables colors in the error message\n"
+    "\t--no-file-contents        Disables '#file_contents' for security\n"
     "\n";
 
 
@@ -62,6 +63,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
         .fun_output              = 0,
         .print_function_mappings = 0,
         .use_post_mvp_features   = 0,
+        .no_file_contents        = 0,
 
         .runtime = Runtime_Wasi,
 
@@ -109,6 +111,9 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
             else if (!strcmp(argv[i], "--no-colors")) {
                 options.no_colors = 1;
             }
+            else if (!strcmp(argv[i], "--no-file-contents")) {
+                options.no_file_contents = 1;
+            }
             else if (!strcmp(argv[i], "--use-post-mvp-features")) {
                 options.use_post_mvp_features = 1;
             }
index b3087ed80c624ed397d12b91b2be2e7fb80ffaab..d9367e79ee75a6bd7ed331f804992866b98d5a04 100644 (file)
@@ -2139,6 +2139,12 @@ void check_entity(Entity* ent) {
 
         case Entity_Type_Process_Directive:        cs = check_process_directive((AstNode *) ent->expr); break;
 
+        case Entity_Type_File_Contents: 
+            if (context.options->no_file_contents) {
+                onyx_report_error(ent->expr->token->pos, "#file_contents is disabled for this compilation.");
+            }
+            break;
+
         default: break;
     }