From owner-freebsd-bugs@FreeBSD.ORG Tue May 20 07:50:04 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 1DB491065675 for ; Tue, 20 May 2008 07:50:04 +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 0B2768FC15 for ; Tue, 20 May 2008 07:50:04 +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 m4K7o3o1046210 for ; Tue, 20 May 2008 07:50:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m4K7o3mD046207; Tue, 20 May 2008 07:50:03 GMT (envelope-from gnats) Date: Tue, 20 May 2008 07:50:03 GMT Message-Id: <200805200750.m4K7o3mD046207@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Jaakko Heinonen 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: Jaakko Heinonen List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 May 2008 07:50:04 -0000 The following reply was made to PR bin/122925; it has been noted by GNATS. From: Jaakko Heinonen To: Bruce Cran Cc: bug-followup@FreeBSD.org, stast@bsdportal.ru Subject: Re: bin/122925: sftp(1) duplicates filename when get listing directory on CDROM Date: Tue, 20 May 2008 10:48:33 +0300 On 2008-05-18, Bruce Cran wrote: > 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. Thanks for the test case. The problem seems to lie in cd9660_readdir() (src/sys/fs/cd9660/cd9660_vnops.c). The problem is that if we have reached end of file (directory) and enter again to cd9660_readdir() the idp->uio_off variable is not initialized correctly. In the end of the function the file offset is set to idp->uio_off. So this basically means that the file offset changes to a random value. This causes effects such readdir(3) starting again at some position or g_vfs_done() errors when data is attempted to read from bogus offset. I believe that this patch fixes the problem: Index: cd9660_vnops.c =================================================================== RCS file: /home/ncvs/src/sys/fs/cd9660/cd9660_vnops.c,v retrieving revision 1.113 diff -p -u -r1.113 cd9660_vnops.c --- cd9660_vnops.c 15 Feb 2007 22:08:34 -0000 1.113 +++ cd9660_vnops.c 20 May 2008 06:45:20 -0000 @@ -495,6 +495,7 @@ cd9660_readdir(ap) } idp->eofflag = 1; idp->curroff = uio->uio_offset; + idp->uio_off = uio->uio_offset; if ((entryoffsetinblock = idp->curroff & bmask) && (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { Could you please test the patch? -- Jaakko