safely abort on exec of uninitialized mem or addr 0

This commit is contained in:
2021-11-27 17:00:44 +01:00
parent d163fb22c5
commit 6e045af565
4 changed files with 11 additions and 4 deletions
+2 -2
View File
@@ -7,8 +7,8 @@
#ifndef FORTH_FH_CONFIG_H
#define FORTH_FH_CONFIG_H
#define DATA_STACK_DEPTH 16
#define RETURN_STACK_DEPTH 16
#define DATA_STACK_DEPTH 256
#define RETURN_STACK_DEPTH 256
#define MAX_NAME_LEN 32
#define HEAP_SIZE (1024*1024)
#define MAXLINE 65535
+1 -1
View File
@@ -30,7 +30,7 @@ enum fh_error {
FH_ERR_NOT_APPLICABLE,
FH_ERR_PICTNUM_FULL,
FH_ERR_BAD_DEFER,
FH_ERR_ABORT, // technical error used to abort from nested input source
FH_ERR_BAD_OPCODE,
FH_ERR_MAX,
};
+1 -1
View File
@@ -23,7 +23,7 @@ static const char *errornames[FH_ERR_MAX] = {
[FH_ERR_PICTNUM_FULL] = "PICTNUM_FULL",
[FH_ERR_NOT_APPLICABLE] = "NOT_APPLICABLE",
[FH_ERR_BAD_DEFER] = "BAD_DEFER",
[FH_ERR_ABORT] = "ABORT",
[FH_ERR_BAD_OPCODE] = "BAD_OPCODE",
};
/** Get error name from code, returns Unknown if not defined */
+7
View File
@@ -161,6 +161,12 @@ enum fh_error w_user_word(struct fh_thread_s *fh, const struct fh_word_s *w0)
}
// make sure it's aligned
fh->execptr = WORDALIGNED(fh->execptr);
if (fh->execptr == 0 || fh->execptr > fh->here) {
LOGE("Bad execptr value 0x%08x", fh->execptr);
return FH_ERR_ILLEGAL_FETCH;
}
const struct fh_instruction_s *instr = fh_instr_at(fh, fh->execptr);
if (!instr) {
LOGE("Execution pointer out of bounds!");
@@ -431,6 +437,7 @@ enum fh_error w_user_word(struct fh_thread_s *fh, const struct fh_word_s *w0)
default:
LOGE("Run handler not implemented for instr opcode %d", instr->kind);
return FH_ERR_BAD_OPCODE;
}
end: