From e9d86eddf348fb8a9852782a4a4b17c594a5c556 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 2 Jun 2014 00:00:51 -0300 Subject: if numeral overflows the reading buffer, signal it as invalid input (resulting in nil) --- liolib.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/liolib.c b/liolib.c index 82fd49f3..ef78da5b 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.124 2014/05/15 15:21:06 roberto Exp $ +** $Id: liolib.c,v 2.125 2014/05/21 15:24:21 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -371,7 +371,7 @@ typedef struct { FILE *f; /* file being read */ int c; /* current character (look ahead) */ int n; /* number of elements in buffer 'buff' */ - char buff[MAXRN]; + char buff[MAXRN + 1]; /* +1 for ending '\0' */ } RN; @@ -379,8 +379,10 @@ typedef struct { ** Add current char to buffer (if not out of space) and read next one */ static int nextc (RN *rn) { - if (rn->n >= MAXRN) /* buffer overflow? */ + if (rn->n >= MAXRN) { /* buffer overflow? */ + rn->buff[0] = '\0'; /* invalidate result */ return 0; /* fail */ + } else { rn->buff[rn->n++] = rn->c; /* save current char */ rn->c = l_getc(rn->f); /* read next one */ -- cgit v1.2.3-55-g6feb