Modify

Ticket #2542 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

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

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

Change History

Changed 5 years ago by ai@…

comment:1 Changed 5 years ago by bemandawes

  • Status changed from new to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.