Date: Sun, 18 May 2008 23:00:03 GMT From: Bruce Cran <bruce@cran.org.uk> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/122925: sftp(1) duplicates filename when get listing directory on CDROM Message-ID: <200805182300.m4IN03CT016374@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/122925; it has been noted by GNATS. From: Bruce Cran <bruce@cran.org.uk> To: bug-followup@FreeBSD.org, stast@bsdportal.ru Cc: Subject: Re: bin/122925: sftp(1) duplicates filename when get listing directory on CDROM Date: Sun, 18 May 2008 23:52:40 +0100 This is occurring because sftp-server expects readdir(3) to return NULL for a given DIR* twice in a row after all the files have been retrieved. It seems that under certain conditions that isn't true. The client sends an FXP_READDIR command; the server loops calling readdir() until it gets a NULL back. At this point it sends the results back to the client, but doesn't appear to tell it it already has all the entries. Instead, the client sends another FXP_READDIR, at which point the server again calls readdir() with the existing DIR*, which has already once before returned NULL. Normally readdir() does return NULL for a second time and the client gets back SSH2_FX_EOF. Occasionally however, readdir will just start reading the directory contents all over again. The following program also shows the same behaviour, but less regularly. #include <stdio.h> #include <sys/types.h> #include <dirent.h> int main() { DIR *dp = opendir("/cdrom/"); if (dp == NULL) return (-1); struct dirent *d = NULL; do { d = readdir(dp); } while (d != NULL); d = readdir(dp); if (d != NULL) printf("readdir is starting again\n"); closedir(dp); return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200805182300.m4IN03CT016374>