aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-08-24 01:26:09 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit40652d7dbf701eda83fa8323b42a6b5bf0ca6bdd (patch)
tree0ada06d4364373a2a7776fc2ac29684e25a9fc31 /src
parent7212ea877ed85d3b85af90c902639df44fc493f2 (diff)
Add sanity checks
Diffstat (limited to 'src')
-rw-r--r--src/program.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/program.c b/src/program.c
index 8a17ac9..55bfda4 100644
--- a/src/program.c
+++ b/src/program.c
@@ -8,6 +8,9 @@
#include <errno.h>
#include <assert.h>
+/* One gigabyte */
+#define PROGRAM_MAX_SIZE 1024*1024*1024
+
/* TODO: If system is big-endian, then do endian conversion for all reads */
/* This matches SsaNumberType */
@@ -136,6 +139,11 @@ static CHECK_RESULT int amal_program_set_exported_function_instruction_offset_ad
}
int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode) {
+ /* Sanity check for indices used later. A program shouldn't be more than 1gb */
+ if(self->data.size + bytecode->data.size > PROGRAM_MAX_SIZE) {
+ amal_log_error("Program is too large. Max size is 1GB");
+ return -1;
+ }
return buffer_append(&self->data, bytecode->data.data, bytecode->data.size);
}
@@ -567,6 +575,10 @@ static CHECK_RESULT int amal_program_read_instructions(amal_program *self, amal_
int amal_program_run(amal_program *self) {
int result;
amal_executor *executor;
+ if(self->data.size > PROGRAM_MAX_SIZE) {
+ amal_log_error("Program is too large. Max size is 1GB");
+ return AMAL_PROGRAM_ERR;
+ }
result = AMAL_PROGRAM_ERR;
return_if_error(amal_executor_init(&executor));