RTEMS | open: Fix race condition when called with O_TRUNC (!178)
Loris Nardo (@loris.nardo)
gitlab at rtems.org
Sat Aug 10 09:41:47 UTC 2024
Loris Nardo commented on a discussion on cpukit/libcsupport/src/open.c: https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/178#note_110820
> if ( rv == 0 ) {
> - rtems_libio_iop_flags_set( iop, LIBIO_FLAGS_OPEN );
> -
> + /*
> + * Postpone the setting of LIBIO_FLAGS_OPEN after the truncation of the
> + * file, this ensures that the file descriptor cannot be used or closed
> + * during or just before the truncation by some other thread.
> + */
> if ( truncate ) {
> - rv = ftruncate( fd, 0 );
> + if ( write_access ) {
> + rv = (*iop->pathinfo.handlers->ftruncate_h)( iop, 0 );
> + } else {
> + rv = -1;
> + errno = EINVAL;
> + }
I've added a blank line, I'm not sure if it is needed also at line 151
--
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/178#note_110820
You're receiving this email because of your account on gitlab.rtems.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20240810/cc7531b2/attachment-0001.htm>
More information about the bugs
mailing list