iris

small scheme interpreter
git clone git://git.2f30.org/iris
Log | Files | Refs | LICENSE

commit 061ae0fa9528d4aa417c0eb339401ab582b28729
parent 6d4badd37658db4818e537e6f60f5eaf32fe0d58
Author: sin <sin@2f30.org>
Date:   Sun, 11 May 2014 16:29:12 +0100

Guard against overwriting the internal lexer buffer

Diffstat:
Mlexer.c | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lexer.c b/lexer.c @@ -58,7 +58,7 @@ gettok(FILE *in) again: state = State_Se; s = e = buf; - while ((c = getc(in)) != EOF) { + while ((c = getc(in)) != EOF && e < &buf[MAXTOKSIZE]) { *e = c; switch (state) { case State_Se: @@ -223,6 +223,12 @@ again: } e++; } + if (e == &buf[MAXTOKSIZE]) { + tok.type = Error; + tok.s = "reached the maximum token size"; + tok.e = NULL; + return tok; + } tok.type = Eof; tok.s = "reached the end-of-file"; tok.e = NULL;