Bug 1236 - SCP inappropriate truncate error when copying to FIFO file
Summary: SCP inappropriate truncate error when copying to FIFO file
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: scp (show other bugs)
Version: 4.3p2
Hardware: ix86 All
: P2 normal
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks: V_4_7
  Show dependency treegraph
 
Reported: 2006-09-25 11:43 AEST by Tom Wood
Modified: 2023-01-13 13:57 AEDT (History)
0 users

See Also:


Attachments
Add test for FIFO file in scp.c prior to truncate attempt. (191 bytes, text/plain)
2006-09-25 11:46 AEST, Tom Wood
no flags Details
Truncate only for regular files that already existed (585 bytes, patch)
2007-06-12 21:26 AEST, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Wood 2006-09-25 11:43:50 AEST
This is an obscure error, but one that I have encountered in a real world application.
When you use scp to copy a file to a remote FIFO file,
the internal function call to ftruncate() has to fail, 
since a FIFO cannot be
truncated to the size of the original file. This results in
a reported error at the command line, even though the data actually
copies as commanded.

Example:
------------------------------------------------------
#scp -B -q afile auser@aserver.com:/tmp/fifofile_input

scp: /tmp/fifofile_input: truncate: Invalid argument
----------------------------------------------
This results in the contents of the file 'afile' being copied
into the remote fifo, but the error is reported and
the exit status is also set to 1.

Suggested fix:
One must add a file status check that the destination file is not
a FIFO file before trying the truncate call (line 994 in unpatched 4.3p2 scp.c).
Comment 1 Tom Wood 2006-09-25 11:46:35 AEST
Created attachment 1189 [details]
Add test for FIFO file in scp.c prior to truncate attempt.
Comment 2 Damien Miller 2007-06-12 21:26:30 AEST
Created attachment 1304 [details]
Truncate only for regular files that already existed

I think this patch is a little better - it will skip the truncate if the file did not already exist or if the target is anything but a regular file.
Comment 3 Tom Wood 2007-06-13 01:20:02 AEST
Damien,
   Your fix to this problem

    "if (wrerr == NO && (!exists || S_ISREG(stb.st_mode)) &&
		    ftruncate(ofd, size) != 0) {"

 looks like it will work just fine with a FIFO file target.This logic
 restricts the ftruncate test much more than my fix. As lonk as
 thats appropriate for all mode types, I agrre it is the right thing to 
 do.
 

Thanks
Tom
Comment 4 Damien Miller 2007-06-13 10:21:12 AEST
Fix applied, this will be in OpenSSH 4.7 - thanks!
Comment 5 Damien Miller 2008-04-04 09:56:18 AEDT
Close resolved bugs after release.