View Issue Details

IDProjectCategoryView StatusLast Update
0018783LazarusIDEpublic2011-02-27 16:00
Reportersamuel herzogAssigned ToMaxim Ganetsky 
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionfixed 
Platformwin32OSxpOS Versionsp3
Product Version0.9.31 (SVN)Product BuildLazarus 0.9.31 r29604 FPC 2.4.3  
Target Version0.9.31 (SVN)Fixed in Version0.9.31 (SVN) 
Summary0018783: [Patch] Crash with "JEDI Code Formater" if path for "Building Test Projects" is not available.
DescriptionIf the path defined in setting "Building Test Projects" does not exist, then the JEDI Code Formater fails to write it's log.
Steps To Reproduce1.) start Lazarus IDE
2.) "New Project"
3.) choose "Environment"->"Options"
4.) set "Directory for building Test-Projects" to an inexistent value.
5.) close the Options dialog by pressing "OK".
6.) Now run "Tools"->"JEDI Code Formatter".

You will get "Invalid filename". Press "OK" to ignore and risk data corruption"
Additional InformationProblem is here:

procedure TJCFLog.OpenLog;
begin
  if not fOpen then
  begin
    AssignFile(FLog, fsLogFileName);
    Rewrite(FLog);

Un-protected file operation. fsLogFileName contains a invalid path.
TagsNo tags attached.
Fixed in Revision29685
LazTarget-
Widgetset
Attached Files
  • 0081783_patch.patch (1,675 bytes)
    Index: JcfLog.pas
    ===================================================================
    --- JcfLog.pas	(revision 29610)
    +++ JcfLog.pas	(working copy)
    @@ -49,7 +49,7 @@
         { worker vars }
         fLog: TextFile;
         { worker procs }
    -    procedure OpenLog;
    +    function OpenLog:boolean;
     
       protected
     
    @@ -81,12 +81,10 @@
     
     procedure TJCFLog.CloseLog;
     begin
    -  if fOpen then
    -  begin
    -    Flush(FLog);
    -    CloseFile(FLog);
    -    fOpen := False;
    -  end;
    +  if not fOpen then exit;
    +  Flush(FLog);
    +  CloseFile(FLog);
    +  fOpen := False;
     end;
     
     constructor TJCFLog.Create(const psFileName: string);
    @@ -106,7 +104,7 @@
     
     procedure TJCFLog.EmptyLine;
     begin
    -  OpenLog;
    +  if not OpenLog then exit;
       WriteLn(Flog, '');
       // no need to flush now - if theprogram dies right here, no new info is lost
     end;
    @@ -115,10 +113,8 @@
     // this one always gets through
     procedure TJCFLog.Write(const ps: string; const peLogLevel: TLogLevel = llMessage);
     begin
    -  if peLogLevel < LogLevel then
    -    exit;
    -
    -  OpenLog;
    +  if peLogLevel < LogLevel then exit;
    +  if not OpenLog then exit;
       WriteLn(Flog, ps);
       Flush(FLog);
     end;
    @@ -128,17 +124,21 @@
       Write(ps, llError);
     end;
     
    -procedure TJCFLog.OpenLog;
    +function TJCFLog.OpenLog:boolean;
     begin
    -  if not fOpen then
    -  begin
    +  result:=true;
    +  if fOpen then exit;
    +  try
         AssignFile(FLog, fsLogFileName);
    +    {$I+}
         Rewrite(FLog);
    +    {$I-}
         fOpen := True;
    -
         { do this no matter what the logging level, unless a log = off level is introduced }
         WriteLn(Flog, 'Logging started at ' + FormatDateTime('dd mmm yyyy hh:mm:ss',
           Date + Time));
    +  except
    +    result:=false;
       end;
     end;
     
    
    0081783_patch.patch (1,675 bytes)

Activities

2011-02-20 06:36

 

0081783_patch.patch (1,675 bytes)
Index: JcfLog.pas
===================================================================
--- JcfLog.pas	(revision 29610)
+++ JcfLog.pas	(working copy)
@@ -49,7 +49,7 @@
     { worker vars }
     fLog: TextFile;
     { worker procs }
-    procedure OpenLog;
+    function OpenLog:boolean;
 
   protected
 
@@ -81,12 +81,10 @@
 
 procedure TJCFLog.CloseLog;
 begin
-  if fOpen then
-  begin
-    Flush(FLog);
-    CloseFile(FLog);
-    fOpen := False;
-  end;
+  if not fOpen then exit;
+  Flush(FLog);
+  CloseFile(FLog);
+  fOpen := False;
 end;
 
 constructor TJCFLog.Create(const psFileName: string);
@@ -106,7 +104,7 @@
 
 procedure TJCFLog.EmptyLine;
 begin
-  OpenLog;
+  if not OpenLog then exit;
   WriteLn(Flog, '');
   // no need to flush now - if theprogram dies right here, no new info is lost
 end;
@@ -115,10 +113,8 @@
 // this one always gets through
 procedure TJCFLog.Write(const ps: string; const peLogLevel: TLogLevel = llMessage);
 begin
-  if peLogLevel < LogLevel then
-    exit;
-
-  OpenLog;
+  if peLogLevel < LogLevel then exit;
+  if not OpenLog then exit;
   WriteLn(Flog, ps);
   Flush(FLog);
 end;
@@ -128,17 +124,21 @@
   Write(ps, llError);
 end;
 
-procedure TJCFLog.OpenLog;
+function TJCFLog.OpenLog:boolean;
 begin
-  if not fOpen then
-  begin
+  result:=true;
+  if fOpen then exit;
+  try
     AssignFile(FLog, fsLogFileName);
+    {$I+}
     Rewrite(FLog);
+    {$I-}
     fOpen := True;
-
     { do this no matter what the logging level, unless a log = off level is introduced }
     WriteLn(Flog, 'Logging started at ' + FormatDateTime('dd mmm yyyy hh:mm:ss',
       Date + Time));
+  except
+    result:=false;
   end;
 end;
 
0081783_patch.patch (1,675 bytes)

samuel herzog

2011-02-20 06:37

developer   ~0046147

Uploaded patch to prevent the problem.

samuel herzog

2011-02-22 06:10

developer   ~0046184

Please review and apply this patch.

Maxim Ganetsky

2011-02-26 19:09

developer   ~0046284

I cannot reproduce it with Lazarus 0.9.31 r29670 FPC 2.4.3 i386-win32-win32/win64 on WinXP SP2.

samuel herzog

2011-02-27 10:45

developer   ~0046289

Did you do step 4 ?

4.) set "Directory for building Test-Projects" to an inexistent value.

Maxim Ganetsky

2011-02-27 13:29

developer   ~0046293

Yes, of course. Can you retest with latest revision and maybe provide a screenshot?

Maxim Ganetsky

2011-02-27 14:18

developer   ~0046294

Anyway, I made log writing logic more robust, so it doesn't try to write to e.g. inaccessible file. Thanks for the hint.

Please test and close if ok.

samuel herzog

2011-02-27 16:00

developer   ~0046298

tested. works. Thank you.

Issue History

Date Modified Username Field Change
2011-02-20 06:11 samuel herzog New Issue
2011-02-20 06:11 samuel herzog LazTarget => -
2011-02-20 06:36 samuel herzog File Added: 0081783_patch.patch
2011-02-20 06:37 samuel herzog Note Added: 0046147
2011-02-22 06:09 samuel herzog Status new => assigned
2011-02-22 06:09 samuel herzog Assigned To => samuel herzog
2011-02-22 06:10 samuel herzog Note Added: 0046184
2011-02-22 06:10 samuel herzog Status assigned => acknowledged
2011-02-22 06:10 samuel herzog Target Version => 0.9.31 (SVN)
2011-02-26 17:51 samuel herzog Summary Crash with "JEDI Code Formater" if path for "Building Test Projects" is not available. => [Patch]Crash with "JEDI Code Formater" if path for "Building Test Projects" is not available.
2011-02-26 17:51 samuel herzog Summary [Patch]Crash with "JEDI Code Formater" if path for "Building Test Projects" is not available. => [Patch] Crash with "JEDI Code Formater" if path for "Building Test Projects" is not available.
2011-02-26 19:09 Maxim Ganetsky Note Added: 0046284
2011-02-26 19:09 Maxim Ganetsky Status acknowledged => feedback
2011-02-26 19:27 Maxim Ganetsky Assigned To samuel herzog =>
2011-02-27 10:45 samuel herzog Note Added: 0046289
2011-02-27 13:29 Maxim Ganetsky Note Added: 0046293
2011-02-27 14:18 Maxim Ganetsky Fixed in Revision => 29685
2011-02-27 14:18 Maxim Ganetsky Status feedback => resolved
2011-02-27 14:18 Maxim Ganetsky Fixed in Version => 0.9.31 (SVN)
2011-02-27 14:18 Maxim Ganetsky Resolution open => fixed
2011-02-27 14:18 Maxim Ganetsky Assigned To => Maxim Ganetsky
2011-02-27 14:18 Maxim Ganetsky Note Added: 0046294
2011-02-27 16:00 samuel herzog Status resolved => closed
2011-02-27 16:00 samuel herzog Note Added: 0046298