Guest User

Delphi: LongString double-free

a guest
Aug 13th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.11 KB | None | 0 0
  1. program Delphi_str_2xFree_Minimized;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. (************************
  6. Delphi Classic compilers bug demonstration: LongString double-free.
  7. Discovered: Arioch on Delphi XE2 Win32
  8. Minimized: nicholaos @ http://www.sql.ru/forum/actualutils.aspx?action=gotomsg&tid=1300873&msg=21640617
  9. Tested by nicholoas: Embarcadero® Delphi 10.2 Version 25.0.26309.314, Win32 & Win64
  10. Reportedly fails with "Illegal Pointer Operator".
  11. Tested by Arioch on XE2 - does not trigger strings de-alloc bug, fails with proper "file not found".
  12. ************************)
  13.  
  14. uses
  15.   IOUtils, SysUtils;
  16. var
  17.   VolatileFN: string;
  18.  
  19. procedure Test(const ConstFN: string); // Hulk crash!
  20. begin
  21.   VolatileFN := Copy(ConstFN, 1, 12);
  22.   TFile.ReadAllText(ConstFN);
  23. end;
  24.  
  25. begin
  26.   try
  27.     try
  28.       VolatileFN := 'c:\Windows\win.ini';
  29.       Test(VolatileFN);
  30.       Writeln('Finished w/o Illegal Pointer Operation');
  31.     except
  32.       on E: Exception do
  33.         Writeln(E.ClassName, ': ', E.Message);
  34.     end;
  35.   finally
  36.     Writeln;
  37.     Writeln('Read the output. Press ENTER to terminate the program.');
  38.     Readln;
  39.   end;
  40. end.
Add Comment
Please, Sign In to add comment