Skip to content
Snippets Groups Projects
Commit ebd19f29 authored by rswindell's avatar rswindell
Browse files

Fix "off-by-one" error in File.readln() and readAll() with regards to the

'maxlen' argument. E.g. passing 10 would result in a maximum read string length
of 9 characters.
parent 9ddb94c6
No related branches found
No related tags found
No related merge requests found
...@@ -533,11 +533,11 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist) ...@@ -533,11 +533,11 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE); return(JS_FALSE);
} }
if((buf=malloc(len))==NULL) if((buf=malloc(len + 1))==NULL)
return(JS_FALSE); return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx); rc=JS_SUSPENDREQUEST(cx);
if(fgets(buf,len,p->fp)!=NULL) { if(fgets(buf,len + 1,p->fp)!=NULL) {
len=strlen(buf); len=strlen(buf);
while(len>0 && (buf[len-1]=='\r' || buf[len-1]=='\n')) while(len>0 && (buf[len-1]=='\r' || buf[len-1]=='\n'))
len--; len--;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment