mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-27 00:50:33 +02:00
* Check buffer overflow when reading
git-svn-id: trunk@49012 -
This commit is contained in:
parent
28e359f091
commit
2a96ad2715
@ -278,6 +278,7 @@ var
|
|||||||
buf : array[0..bufsize-1] of byte;
|
buf : array[0..bufsize-1] of byte;
|
||||||
bufptr : pbyte;
|
bufptr : pbyte;
|
||||||
bufbytes : tsSize;
|
bufbytes : tsSize;
|
||||||
|
bufoverflow : boolean;
|
||||||
f : longint;
|
f : longint;
|
||||||
tzhead : ttzhead;
|
tzhead : ttzhead;
|
||||||
|
|
||||||
@ -288,22 +289,22 @@ var
|
|||||||
readfilebuf:=bufbytes;
|
readfilebuf:=bufbytes;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure checkbufptr;
|
Procedure checkbufptr(asize : integer);
|
||||||
|
|
||||||
var
|
var
|
||||||
a : tssize;
|
a : tssize;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
a:=bufptr-@buf;
|
a:=bufptr-@buf+asize;
|
||||||
if (a>bufbytes) then
|
if (a>bufbytes) then
|
||||||
Writeln('Reading past end of file : ',a);
|
bufoverflow:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function readbufbyte: byte;
|
function readbufbyte: byte;
|
||||||
begin
|
begin
|
||||||
// checkbufptr;
|
|
||||||
if bufptr > @buf[bufsize-1] then
|
if bufptr > @buf[bufsize-1] then
|
||||||
readfilebuf;
|
readfilebuf;
|
||||||
|
checkbufptr(1);
|
||||||
readbufbyte := bufptr^;
|
readbufbyte := bufptr^;
|
||||||
inc(bufptr);
|
inc(bufptr);
|
||||||
end;
|
end;
|
||||||
@ -319,13 +320,13 @@ var
|
|||||||
numbytes := count;
|
numbytes := count;
|
||||||
if numbytes > 0 then
|
if numbytes > 0 then
|
||||||
begin
|
begin
|
||||||
|
checkbufptr(numbytes);
|
||||||
if assigned(dest) then
|
if assigned(dest) then
|
||||||
move(bufptr^, dest^, numbytes);
|
move(bufptr^, dest^, numbytes);
|
||||||
inc(bufptr, numbytes);
|
inc(bufptr, numbytes);
|
||||||
dec(count, numbytes);
|
dec(count, numbytes);
|
||||||
inc(readbuf, numbytes);
|
inc(readbuf, numbytes);
|
||||||
inc(dest, numbytes);
|
inc(dest, numbytes);
|
||||||
// checkbufptr;
|
|
||||||
end;
|
end;
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
readfilebuf
|
readfilebuf
|
||||||
@ -462,10 +463,11 @@ begin
|
|||||||
f:=fpopen(fn,Open_RdOnly);
|
f:=fpopen(fn,Open_RdOnly);
|
||||||
if f<0 then
|
if f<0 then
|
||||||
exit(False);
|
exit(False);
|
||||||
|
bufoverflow:=false;
|
||||||
bufptr := @buf[bufsize-1]+1;
|
bufptr := @buf[bufsize-1]+1;
|
||||||
tzhead:=default(ttzhead);
|
tzhead:=default(ttzhead);
|
||||||
LockTZInfo;
|
LockTZInfo;
|
||||||
ReadTimezoneFile:=(readheader() and readdata());
|
ReadTimezoneFile:=(readheader() and readdata()) and not BufOverflow;
|
||||||
ClearCurrentTZinfo;
|
ClearCurrentTZinfo;
|
||||||
UnlockTZInfo;
|
UnlockTZInfo;
|
||||||
fpclose(f);
|
fpclose(f);
|
||||||
|
Loading…
Reference in New Issue
Block a user