FpReadDir under BSDs may return some random crap
Original Reporter info from Mantis: FPCCore
-
Reporter name: FPC core team
Original Reporter info from Mantis: FPCCore
- Reporter name: FPC core team
Description:
When trying to enumerate files in some directories (using FpOpen/Read/CloseDir or their wrappers FindFirst/Next) more than once (i.e. read one directory, and then read another one) some strange random things may be returned by FpReadDir. This was observed by me only under FreeBSD. Bug does not occur under Linux and does not occur under FreeBSD when RTL is compiled with -dFPC_USE_LIBC. It seems to me that this happens because FpReadDir reads memory that wasn't actually initialized by getents call. I managed to solve this by these changes to rtl/bsd/ossysc.inc:
Index: ossysc.inc
===================================================================
RCS file: /FPC/CVS/fpc/rtl/bsd/ossysc.inc,v
retrieving revision 1.20
diff -u -r1.20 ossysc.inc
--- ossysc.inc 14 Nov 2004 12:21:08 -0000 1.20
+++ ossysc.inc 7 Jan 2005 03:10:34 -0000
@@ -286,6 +286,7 @@
end
else
dirP^.dd_loc:=retval;
+ dirP^.dd_size := retval;
readbuffer:=retval;
end;
@@ -299,7 +300,7 @@
if (dirp^.dd_buf=nil) or (dirp^.dd_loc=0) THEN
exit(nil);
if (dirp^.dd_loc=-1) OR {First readdir on this pdir. Initial fill of buffer}
- (dirp^.dd_rewind>=(longint(dirp^.dd_buf)+dirblksiz)) then {no more entries left?}
+ (dirp^.dd_rewind>=(longint(dirp^.dd_buf) + dirP^.dd_size)) then {no more entries left?}
Begin
if readbuffer=0 then {succesful read?}
Exit(NIL); {No more data}
Additional information:
Reporter: Michalis Kamburelis
EMail: michalis at camelot dot homedns dot org
Mantis conversion info:
- Mantis ID: 5510
- OS: FreeBSD
- Version: 1.9.7
- Fixed in version: 1.9.9