From owner-freebsd-bugs@FreeBSD.ORG Sun May 18 23:00:03 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE17F1065671 for ; Sun, 18 May 2008 23:00:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A9B248FC15 for ; Sun, 18 May 2008 23:00:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m4IN03VN016375 for ; Sun, 18 May 2008 23:00:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m4IN03CT016374; Sun, 18 May 2008 23:00:03 GMT (envelope-from gnats) Date: Sun, 18 May 2008 23:00:03 GMT Message-Id: <200805182300.m4IN03CT016374@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Cran Cc: Subject: Re: bin/122925: sftp(1) duplicates filename when get listing directory on CDROM X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Bruce Cran List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 May 2008 23:00:03 -0000 The following reply was made to PR bin/122925; it has been noted by GNATS. From: Bruce Cran 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 #include #include 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; }