Skip to content

Fix full_write on incomplete write#415

Merged
cgzones merged 1 commit intologrotate:masterfrom
cgzones:full_write
Aug 24, 2021
Merged

Fix full_write on incomplete write#415
cgzones merged 1 commit intologrotate:masterfrom
cgzones:full_write

Conversation

@cgzones
Copy link
Member

@cgzones cgzones commented Aug 7, 2021

Currently on an incomplete write(3) the subsequent write(3) will again
use the same starting position in the given buffer, which was already
successfully written, leading to data corruption.

Found by clang-13

logrotate.c:1140:17: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
const char *ptr = (const char *) buf;
            ^

Fixes: f1dc0d9 ("Allow rotation of sparse files with copytruncate")

@cgzones cgzones added the bug label Aug 7, 2021
@cgzones cgzones requested a review from kdudka August 7, 2021 16:28
@kdudka
Copy link
Member

kdudka commented Aug 10, 2021

The actual fix looks good. I am not sure about the added unsigned -- does it help in any way?

Another preexisting issue with the code is that it should not check the value of errno unless write() returns -1.

Currently on an incomplete write(2) the subsequent write(2) will again
use the same starting position in the given buffer, which was already
successfully written, leading to data corruption.

Found by clang-13

    logrotate.c:1140:17: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
    const char *ptr = (const char *) buf;
                ^

Also check for EINTR only on write(2) failure.
Also use `unsigned char *` to signal handling bytes, not a string.

Fixes: f1dc0d9 ("Allow rotation of sparse files with copytruncate")
@cgzones
Copy link
Member Author

cgzones commented Aug 10, 2021

Another preexisting issue with the code is that it should not check the value of errno unless write() returns -1.

True, I updated the patch.

Copy link
Member

@kdudka kdudka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for the update!

@cgzones cgzones merged commit eb7ec2b into logrotate:master Aug 24, 2021
@cgzones cgzones deleted the full_write branch August 24, 2021 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants