Opened 14 years ago

Closed 14 years ago

#2542 closed Bugs (fixed)

filesystem: wrong close 0 descriptor in copy_file_api on unix

Reported by: ai@… Owned by:
Milestone: Boost 1.38.0 Component: None
Version: Boost 1.37.0 Severity: Problem
Keywords: Cc:

Description

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;

Attachments (1)

operations.patch (449 bytes ) - added by ai@… 14 years ago.

Download all attachments as: .zip

Change History (2)

by ai@…, 14 years ago

Attachment: operations.patch added

comment:1 by Beman Dawes, 14 years ago

Resolution: fixed
Status: newclosed

(In [50033]) Filesystem: fix #2542, wrong close 0 descriptor in copy_file_api on unix

Note: See TracTickets for help on using tickets.