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
Branches
Tags
No related merge requests found
......@@ -533,11 +533,11 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
if((buf=malloc(len))==NULL)
if((buf=malloc(len + 1))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
if(fgets(buf,len,p->fp)!=NULL) {
if(fgets(buf,len + 1,p->fp)!=NULL) {
len=strlen(buf);
while(len>0 && (buf[len-1]=='\r' || buf[len-1]=='\n'))
len--;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment