Opened 8 years ago

Closed 8 years ago

#10506 closed Bugs (fixed)

Infinite loop in create_or_open_file

Reported by: kevin.arunski@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: interprocess
Version: Boost 1.56.0 Severity: Problem
Keywords: Cc:

Description

This function will never exit if the call to ::open returns -1 for a reason other than EEXIST.

inline file_handle_t create_or_open_file

(const char *name, mode_t mode, const permissions & perm = permissions(), bool temporary = false)

{

(void)temporary; int ret = -1; We need a loop to change permissions correctly using fchmod, since with "O_CREAT only" ::open we don't know if we've created or opened the file. while(1){

ret = ::open(name, ((int)mode) | O_EXCL | O_CREAT, perm.get_permissions()); if(ret >= 0){

::fchmod(ret, perm.get_permissions()); break;

} else if(errno == EEXIST){

if((ret = ::open(name, (int)mode)) >= 0
errno != ENOENT){

break;

}

}

} return ret;

}

For example if the call fails due to errno == EACCESS, the function does not exit.

Change History (1)

comment:1 by Ion Gaztañaga, 8 years ago

Resolution: fixed
Status: newclosed

Thanks for the report. Fixed in:

[develop 2c4f35f] Fixes Trac #10506

If error is not EEXIST, goes out of the loop

Note: See TracTickets for help on using tickets.