Skip to content
Snippets Groups Projects
Commit c920d0da authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix possible negative offset to lseek()

CID 327965
parent 4f11e1df
Branches
Tags
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -406,15 +406,18 @@ js_raw_read(JSContext *cx, uintN argc, jsval *arglist)
* required by POSIX.
*/
fflush(p->fp);
pos = ftell(p->fp);
fd = fileno(p->fp);
lseek(fd, pos, SEEK_SET);
len = read(fileno(p->fp),buf,len);
fseeko(p->fp, pos + (len >= 0 ? len : 0), SEEK_SET);
dbprintf(FALSE, p, "read %u raw bytes",len);
if(len<0)
len=0;
pos = ftello(p->fp);
if(pos < 0)
len = 0;
else {
fd = fileno(p->fp);
lseek(fd, pos, SEEK_SET);
len = read(fileno(p->fp),buf,len);
fseeko(p->fp, pos + (len >= 0 ? len : 0), SEEK_SET);
dbprintf(FALSE, p, "read %d raw bytes",len);
if(len<0)
len=0;
}
JS_RESUMEREQUEST(cx, rc);
str = JS_NewStringCopyN(cx, buf, len);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment