aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-02 00:00:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-06-02 00:00:51 -0300
commite9d86eddf348fb8a9852782a4a4b17c594a5c556 (patch)
tree229d862b1f25d94c16f2f38031adcee493ebf22a
parent11aefa447827972064e2d51b6c5ce3a3aede01cf (diff)
downloadlua-e9d86eddf348fb8a9852782a4a4b17c594a5c556.tar.gz
lua-e9d86eddf348fb8a9852782a4a4b17c594a5c556.tar.bz2
lua-e9d86eddf348fb8a9852782a4a4b17c594a5c556.zip
if numeral overflows the reading buffer, signal it as invalid input
(resulting in nil)
-rw-r--r--liolib.c8
1 files 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 @@
1/* 1/*
2** $Id: liolib.c,v 2.124 2014/05/15 15:21:06 roberto Exp $ 2** $Id: liolib.c,v 2.125 2014/05/21 15:24:21 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -371,7 +371,7 @@ typedef struct {
371 FILE *f; /* file being read */ 371 FILE *f; /* file being read */
372 int c; /* current character (look ahead) */ 372 int c; /* current character (look ahead) */
373 int n; /* number of elements in buffer 'buff' */ 373 int n; /* number of elements in buffer 'buff' */
374 char buff[MAXRN]; 374 char buff[MAXRN + 1]; /* +1 for ending '\0' */
375} RN; 375} RN;
376 376
377 377
@@ -379,8 +379,10 @@ typedef struct {
379** Add current char to buffer (if not out of space) and read next one 379** Add current char to buffer (if not out of space) and read next one
380*/ 380*/
381static int nextc (RN *rn) { 381static int nextc (RN *rn) {
382 if (rn->n >= MAXRN) /* buffer overflow? */ 382 if (rn->n >= MAXRN) { /* buffer overflow? */
383 rn->buff[0] = '\0'; /* invalidate result */
383 return 0; /* fail */ 384 return 0; /* fail */
385 }
384 else { 386 else {
385 rn->buff[rn->n++] = rn->c; /* save current char */ 387 rn->buff[rn->n++] = rn->c; /* save current char */
386 rn->c = l_getc(rn->f); /* read next one */ 388 rn->c = l_getc(rn->f); /* read next one */