TRegIniFile crash on WriteXXX if Filename in constructor starts with '\'
Original Reporter info from Mantis: Bart @flyingsheep
-
Reporter name: Bart Broersma
Original Reporter info from Mantis: Bart @flyingsheep
- Reporter name: Bart Broersma
Description:
If you Create a TRegIni instance and the FN paramter in Create() starts with a backslash, then any attempt to write a value to the registry will fail with a message like:
ERegistryException: Failed to create key: "\Software\FSI2\RegIni\NewSection"
Steps to reproduce:
Given the following example program:
program rtest;
{$apptype console}
{$ifdef fpc}{$mode objfpc}{$endif}
uses
registry, sysutils, classes {$ifndef fpc}, windows{$endif};
var
RegIni: TRegIniFile;
WFileName, S: String;
i: Integer;
begin
RegIni := TRegIniFile.Create('\Software\FSI2\RegIni');
try
writeln('Created RegIni');
RegIni.RootKey := HKEY_CURRENT_USER;
writeln(format('Filename = "%s"',[RegIni.FileName]));
S := RegIni.ReadString('NewSection','NewString','Failure!');
writeln(format('S = "%s"',[S]));
RegIni.WriteString('NewSection','NewString','Success');
S := RegIni.ReadString('NewSection','NewString','Failure!');
writeln(format('S = "%s"',[S]));
finally
RegIni.Free;
end;
end.
Build and run with Delphi (7):
C:\Users\Bart\LazarusProjecten\bugs\Console\regini>dcc32 rtest.lpr
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
rtest.lpr(44)
45 lines, 0.05 seconds, 74344 bytes code, 3625 bytes data.
C:\Users\Bart\LazarusProjecten\bugs\Console\regini>rtest
Created RegIni
Filename = "\Software\FSI2\RegIni"
S = "Failure!" //expected since the key does not exist yet.
S = "Success"
Build and run with fpc:
C:\Users\Bart\LazarusProjecten\bugs\Console\regini>fpc rtest.lpr
Free Pascal Compiler version 3.1.1 [2018/06/03] for i386
Copyright (c) 1993-2018 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling rtest.lpr
Linking rtest.exe
43 lines compiled, 0.2 sec, 151680 bytes code, 6628 bytes data
C:\Users\Bart\LazarusProjecten\bugs\Console\regini>rtest
Created RegIni
Filename = "\Software\FSI2\RegIni"
S = "Failure!"
An unhandled exception occurred at $0040F9DB:
ERegistryException: Failed to create key: "\\Software\FSI2\RegIni\NewSection"<br/>
$0040F9DB
$004100D0
$0040FF4D
$0040185D
Mantis conversion info:
- Mantis ID: 33993
- OS: Windows
- OS Build: 10
- Build: r39352
- Platform: i386
- Version: 3.1.1
- Fixed in version: 3.3.1
- Fixed in revision: 39659 (#e6304da9)
- Target version: 3.2.0