Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openrc-shutdown: broadcast: avoid double fclose #707

Closed
wants to merge 1 commit into from

Conversation

floppym
Copy link
Contributor

@floppym floppym commented May 21, 2024

Initialize fd and tp to known invalid values, and reset them after
calling close/fclose. This is necessary since these are decleared as
static variables.

Note the close will will likely still be called twice: we close fd
before tp to avoid any buffered writes.

Bug: https://bugs.gentoo.org/923326

@floppym floppym force-pushed the bug923326 branch 2 times, most recently from 4baacad to eddb17b Compare May 21, 2024 18:43
if (fd >= 0)
/*
* It is possible we got here because fputs or fflush got
* interrupted by SIGALARM. Close the file descriptor first to
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this result in a double close of fd?
If blocking is the issue why not make the fd non-blocking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it does result in a double close. I should update the summary: the bug is a double fclose, since that causes a double free.

The fd is already non-blocking, but the original author doesn't trust the kernel to respect that apparently. The whole SIGALARM path should really be stripped out and simplified.

Initialize fd and tp to known invalid values, and reset them after
calling close/fclose. This is necessary since these are decleared as
static variables.

Note the close will will likely still be called twice: we close fd
before tp to avoid any buffered writes.

Bug: https://bugs.gentoo.org/923326
Signed-off-by: Mike Gilbert <[email protected]>
@floppym floppym changed the title openrc-shutdown: broadcast: avoid double close openrc-shutdown: broadcast: avoid double fclose May 23, 2024
@floppym
Copy link
Contributor Author

floppym commented May 23, 2024

Closing in favor of #709.

@floppym floppym closed this May 23, 2024
@floppym floppym deleted the bug923326 branch May 28, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants