SHARE
TWEET

Delphi: LongString double-free

a guest Aug 13th, 2018 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top