-
Notifications
You must be signed in to change notification settings - Fork 143
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
Fix FD leak when checking lock dir permissions #216
Fix FD leak when checking lock dir permissions #216
Conversation
42ab876
to
60bdce0
Compare
`mkstemp(3)` creates and opens a file descriptor for a temporary file, but this file descriptor was immediately discarded in favour of `fopen(3)`'ing the file by name and using that `FILE *` stream. I'm sure whoever originally wrote this code meant to use `mktemp(3)` instead, which only creates a unique file from a template name (equivalent to `mktemp(1)`).
60bdce0
to
2d3743e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice finding! I second your theory. Maybe it used to be mktemp(3)
and somebody replaced it by mkstemp(3)
without thinking much about it, because the man page of mktemp(3)
discourages its use:
Never use mktemp(). Some implementations follow 4.3BSD and replace XXXXXX by the current process ID and a single letter, so that at most 26 different names can be returned. Since on the one hand the names are easy to guess, and on the other hand there is a race between testing whether the name exists and opening the file, every use of mktemp() is a security risk. The race is avoided by mkstemp(3).
I think this limitation is okay for us...
Yeah, I saw that. I thought about leaning into the
Given that I'd like to replace all the lock file stuff with native Java implementations anyway, I'm more comfortable with this smaller change for now. |
Fully agree.
🤷
Looking forward to it! |
I've confirmed that this does fix the issue. I wrote a small program to print the results of I'm going to try to finish up #211 then work toward cutting a new release (v5.2.2). |
@MrDOS Thanks for all the hard work on this library! Regarding 5.2.2, any thoughts on when you might have a release? I would love to see this fix in openHAB soon! Any chance maybe to push the open issues in https://github.com/NeuronRobotics/nrjavaserial/milestone/2 to a 5.2.3 release ? |
mkstemp(3)
creates and opens a file descriptor for a temporary file, but this file descriptor was immediately discarded in favour offopen(3)
'ing the file by name and using thatFILE *
stream. I'm sure whoever originally wrote this code meant to usemktemp(3)
instead, which only creates a unique file from a template name (equivalent tomktemp(1)
).This fixes openhab/openhab-core#1842 and mitigates #111.