Bug 1375

Summary: sftp-client leaks handles on failure to open local file
Product: Portable OpenSSH Reporter: Scott Worley <sworley>
Component: sftpAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: minor CC: djm
Priority: P2    
Version: 4.7p1   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 1353    
Attachments:
Description Flags
do_close(handle) on local file open failure none

Description Scott Worley 2007-10-16 04:20:03 AEST
Created attachment 1362 [details]
do_close(handle) on local file open failure

I get "Couldn't get handle: Failure" after N failures to open local files for writing where N = 100 on OpenBSD and N = 200 on GNU/Linux.


To reproduce:
bash-3.2$ ssh otherhost
otherhost$ mkdir test
otherhost$ cd test
otherhost$ touch {1000..1120}
otherhost$ logout
Connection to otherhost closed.
bash-3.2$ mkdir test
bash-3.2$ cd test
bash-3.2$ touch {1000..1110}
bash-3.2$ chmod 400 *
bash-3.2$ sftp otherhost
Connecting to otherhost...
sftp> cd test
sftp> get *
Fetching /home/user/test/1000 to 1000
Couldn't open local file "1000" for writing: Permission denied
Fetching /home/user/test/1001 to 1001
Couldn't open local file "1001" for writing: Permission denied
...
Fetching /home/user/test/1099 to 1099
Couldn't open local file "1099" for writing: Permission denied
Fetching /home/user/test/1100 to 1100
Couldn't get handle: Failure
Fetching /home/user/test/1101 to 1101
Couldn't get handle: Failure
...
Fetching /home/user/test/1120 to 1120
Couldn't get handle: Failure
sftp> ls
Couldn't get handle: Failure




The attached patch seems to fix the problem.
Comment 1 Damien Miller 2008-01-20 09:05:15 AEDT
fix applied - thanks!
Comment 2 Damien Miller 2008-03-31 15:21:43 AEDT
Fix shipped in 4.9/4.9p1 release.