link(2) to rename files in sftp

Markus Friedl markus at openbsd.org
Tue Apr 6 23:57:06 EST 2004


On Tue, Apr 06, 2004 at 05:16:54PM +0400, Dan Yefimov wrote:
> May be the following code could be used:
> 
> 	if ((ret = open(newpath, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR)) != -1) {
> 		close(ret);
> 		ret = rename(oldpath, newpath);
> 		status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
> 	}
> 
> Of course, someone could modify temporary file mode and write something into it 
> between calls to open() and rename() are made, but does somebody really care 
> about that case?

this contains the same race as the original code.




More information about the openssh-unix-dev mailing list