|
Boost : |
Subject: [boost] filesystem: wrong close 0 descriptor in copy_file_api on unix
From: Anton Ivanov (ai_at_[hidden])
Date: 2008-11-29 10:16:03
Hi!
Seems bug in boost::filesystem::copy_file on unix.
This code is wrong if ::stat call fails - it is just close descriptor
with number 0 (by if ( infile >= 0 ) ::close( infile );).
BOOST_FILESYSTEM_DECL error_code copy_file_api( const std::string &
from_file_ph,
const std::string & to_file_ph )
{
const std::size_t buf_sz = 32768; boost::scoped_array<char> buf(
new char [buf_sz] ); int infile=0, outfile=0; // init quiets compiler
warning struct stat from_stat;
if ( ::stat( from_file_ph.c_str(), &from_stat ) != 0
(infile = ::open( from_file_ph.c_str(),
O_RDONLY )) < 0
(outfile = ::open( to_file_ph.c_str(),
O_WRONLY | O_CREAT | O_EXCL, from_stat.st_mode )) < 0 )
{
if ( infile >= 0 ) ::close( infile ); return error_code(
errno, system_category );
}
Fix is just changing
int infile=0, outfile=0; // init quiets compiler warning
to
int infile=-1, outfile=-1;
Patch attached.
Bug
https://svn.boost.org/trac/boost/ticket/2542
created.
-- Yours sincerely, Anton Ivanov (ai_at_[hidden])
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk