leeonsoft / txquery

Automatically exported from code.google.com/p/txquery
Other
0 stars 0 forks source link

Buffer overrun in procedure ReadLn in unit QLexLib #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Subprocedure CheckBuffer in procedure ReadLn (unit QLexLib) doesn't take into 
account SizeOf(Char) when checking buffer size and allocating buffer. Existing 
procedure should be changed to

  procedure CheckBuffer;
  begin
    repeat
      //we need to take into account size of char - we are increasing
      //position in stream by SizeOf(char) and not by a byte
      if (i * SizeOf(Char)) >= (BufSize - SizeOf(Char)) then
      //(- SizeOf(Char) is needed if BufSize is odd number and
      //GetMem works in chunks of 1 byte
      begin
        BufSize := max (BufSize * 2, 256);
        ReallocMem (Buf, BufSize);
      end;
    until (i * SizeOf(Char)) < (BufSize - SizeOf(Char));
  end;

Original issue reported on code.google.com by greg....@gmail.com on 27 Jul 2010 at 10:48

GoogleCodeExporter commented 9 years ago
This helped me. Thanks Greg. I had this same exact problem. Your code fix 
worked like a champ!
Regards,
Tony Marelich

Original comment by tmarel...@gmail.com on 12 Oct 2010 at 5:48