bin/122925: sftp(1) duplicates filename when get listing directory on CDROM

Jaakko Heinonen jh at saunalahti.fi
Tue May 20 07:50:04 UTC 2008


The following reply was made to PR bin/122925; it has been noted by GNATS.

From: Jaakko Heinonen <jh at saunalahti.fi>
To: Bruce Cran <bruce at cran.org.uk>
Cc: bug-followup at FreeBSD.org, stast at 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


More information about the freebsd-bugs mailing list