View Issue Details

IDProjectCategoryView StatusLast Update
0037133LazarusIDEpublic2020-05-24 10:49
ReporterCyrax Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformLinux x86_64OSArch 
Product Version2.1 (SVN) 
Summary0037133: Running lazbuild through valgrind shows that a empty string is passed to SysUtils.DIRECTORYEXISTS function.
DescriptionI have noticed random crashes at lazbuild when trying to build same project to different targets.
Trying to fix these crashes by using valgrind, it is have notified me that there is something odd when calling DirectoryExists function.

See Additional Information field for more info.
Additional Information
==63588== Syscall param stat(file_name) points to unaddressable byte(s)
==63588==    at 0x40D104: SYSTEM_$$_FPSYSCALL$INT64$INT64$INT64$$INT64 (syscall.inc:80)
==63588==    by 0x40DFAE: SYSTEM_$$_FPSTAT$PCHAR$STAT$$LONGINT (ossysc.inc:121)
==63588==    by 0x4C0479: SYSUTILS_$$_DIRECTORYEXISTS$RAWBYTESTRING$BOOLEAN$$BOOLEAN (sysutils.pp:693)
==63588==    by 0x4DD47E: LAZFILEUTILS_$$_DIRECTORYEXISTSUTF8$ANSISTRING$$BOOLEAN (unixlazfileutils.inc:47)
==63588==    by 0x4E03E9: LAZFILEUTILS_$$_DIRPATHEXISTS$ANSISTRING$$BOOLEAN (lazfileutils.pas:520)
==63588==    by 0x4E067F: LAZFILEUTILS_$$_FORCEDIRECTORY$ANSISTRING$$BOOLEAN (lazfileutils.pas:552)
==63588==    by 0x405B3E: P$LAZBUILD$_$TLAZBUILDAPPLICATION_$_BUILDPROJECT$ANSISTRING$$BOOLEAN_$$_STARTBUILDING$$BOOLEAN (lazbuild.lpr:836)
==63588==    by 0x404EB3: P$LAZBUILD$_$TLAZBUILDAPPLICATION_$__$$_BUILDPROJECT$ANSISTRING$$BOOLEAN (lazbuild.lpr:937)
==63588==    by 0x402C2C: P$LAZBUILD$_$TLAZBUILDAPPLICATION_$__$$_BUILDFILE$ANSISTRING$$BOOLEAN (lazbuild.lpr:426)
==63588==    by 0x409E00: P$LAZBUILD$_$TLAZBUILDAPPLICATION_$__$$_RUN (lazbuild.lpr:1475)
==63588==    by 0x40D065: main (lazbuild.lpr:1878)
==63588==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 2
Attached Files

Activities

Cyrax

2020-05-23 20:32

reporter   ~0123016

Running valgrind throught vgdb proxy and using it as remote target for GDB debugger running under the IDE and the project , Lazarus have stopped at SIGTRAP.

Call stack follows :
#0 FPSYSCALL(0, 137422174456, 137422174456) at x86_64/syscall.inc:80
0000001 FPSTAT(0x0, {ST_DEV = 6148914691236517205, ST_INO = 6148914691236517205, ST_NLINK = 6148914691236517205, ST_MODE = 1431655765, ST_UID = 1431655765, ST_GID = 1431655765, __PAD1 = 1431655765, ST_RDEV = 6148914691236517205, ST_SIZE = 6148914691236517205, ST_BLKSIZE = 6148914691236517205, ST_BLOCKS = 6148914691236517205, ST_ATIME = 6148914691236517205, ST_ATIME_NSEC = 6148914691236517205, ST_MTIME = 6148914691236517205, ST_MTIME_NSEC = 6148914691236517205, ST_CTIME = 6148914691236517205, ST_CTIME_NSEC = 6148914691236517205, __UNUSED2 = {6148914691236517205, 6148914691236517205, 6148914691236517205}}) at ossysc.inc:121
0000002 DIRECTORYEXISTS(0x0, true) at ../unix/sysutils.pp:693
0000003 DIRECTORYEXISTSUTF8(0x0) at unixlazfileutils.inc:47
0000004 DIRPATHEXISTS(0x0) at lazfileutils.pas:520
0000005 FORCEDIRECTORY(0x7340b90 '/mnt/shares/ohjelmointi/3'...) at lazfileutils.pas:552
0000006 STARTBUILDING(0x1ffeffffa0) at lazbuild.lpr:836
0000007 BUILDPROJECT(0x4c49f08, 0x4c54c90 '/mnt/shares/ohjelmointi/3'...) at lazbuild.lpr:937
0000008 BUILDFILE(0x4c49f08, 0x4c54c90 '/mnt/shares/ohjelmointi/3'...) at lazbuild.lpr:426
0000009 RUN(0x4c49f08) at lazbuild.lpr:1475
0000010 main at lazbuild.lpr:1878

Martok

2020-05-23 20:34

reporter   ~0123017

Last edited: 2020-05-23 20:38

View 2 revisions

Could this be related to 0037034? Some string operations appear to be broken.

Cyrax

2020-05-23 20:43

reporter   ~0123019

Last edited: 2020-05-23 20:48

View 2 revisions

Hmm, I don't know. It seems that Windows target is broken, not others.

See this code snippet from lazfileutils.pas unit:
function ForceDirectory(DirectoryName: string): boolean;
var i: integer;
  Dir: string;
begin
  DirectoryName:=AppendPathDelim(DirectoryName);
  i:=1;
  while i<=length(DirectoryName) do begin
    if DirectoryName[i] in AllowDirectorySeparators then begin
      Dir:=copy(DirectoryName,1,i-1);
      if not DirPathExists(Dir) then begin
        Result:=CreateDirUTF8(Dir);
        if not Result then exit;
      end;
    end;
    inc(i);
  end;
  Result:=true;
end;


At beginning loop and variable i is 1, this clause (copy) will return empty string.
Dir:=copy(DirectoryName,1,i-1);


This will trigger valgrind.
If I remove -1 expression off, valgrind is happy and will continue execution.
There should be check for empty string or just remove the -1.

Bart Broersma

2020-05-24 10:47

developer   ~0123028

Last edited: 2020-05-24 10:48

View 2 revisions

Adding some debug statments shows (Windows):
Dir="", DirPathExists(Dir)=FALSE
CreateDirUTF8("")=TRUE
Dir="\mnt", DirPathExists(Dir)=FALSE
CreateDirUTF8("\mnt")=TRUE
Dir="\mnt\shares", DirPathExists(Dir)=FALSE
CreateDirUTF8("\mnt\shares")=TRUE
Dir="\mnt\shares\ohjelmointi", DirPathExists(Dir)=FALSE
CreateDirUTF8("\mnt\shares\ohjelmointi")=TRUE
Dir="\mnt\shares\ohjelmointi\3", DirPathExists(Dir)=FALSE
CreateDirUTF8("\mnt\shares\ohjelmointi\3")=TRUE

CreateDir(EmptyStr) returns True, so this should not really matter.

You can create a patch to optimize this.
Notice however that CreateDirectory(EmptyStr) should still return True.

Issue History

Date Modified Username Field Change
2020-05-23 20:28 Cyrax New Issue
2020-05-23 20:32 Cyrax Note Added: 0123016
2020-05-23 20:34 Martok Note Added: 0123017
2020-05-23 20:38 Martok Note Edited: 0123017 View Revisions
2020-05-23 20:43 Cyrax Note Added: 0123019
2020-05-23 20:48 Cyrax Note Edited: 0123019 View Revisions
2020-05-24 10:47 Bart Broersma Note Added: 0123028
2020-05-24 10:48 Bart Broersma Note Edited: 0123028 View Revisions