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
reopen_standard_stream contains nonsensical mix of fd-level and FILE-level operations, can corrupt C library state #64
Comments
Hello team, Let me explain the steps to reproduce. The example_cmdlib.c works fine. https://github.com/lvmteam/lvm2/blob/master/doc/example_cmdlib.c
The print( ) AIP in test_log_fn doesn't work when I define my_function.
|
The core problem was ensure what kind of buffering glibc will use - and since lvm2 works across numerous version of glibc - various versions seemed to have different problems with our major requirement to use already preallocated buffer (so glibc does not resize/reallocate it's internal stream buffers later while i.e. buffering log output while we do not want any allocation/mmap to happen. So while the code might look weird we are not aware of any crashes/memory leak with current solution - if there is any - please report as bug with reproducer. As we no longer support any library usage from lvm (user should stay with call of lvm command - eventually they may try D-Bus - although this API has its limits) - I'm not quite sure what is 2nd. comment about ?? |
This part of
reopen_standard_stream
mixes operations at the fd level with operations at the FILE level in a way that doesn't make any sense to me and, as reported (somewhat incoherently) at https://stackoverflow.com/questions/70879665/ , can wind up corrupting the C library's internal state associated withstdout
. Also, several of the error handling paths are incorrect and would cause either crashes or file descriptor leaks.To the extent I understand what this is trying to do, it looks like a corrected version would be
That is, don't try to close the original FILE object at all, just make a second FILE pointing to a duplicate of the original file descriptor, which the library can use internally as it sees fit.
It's possible that my suggestion doesn't accomplish what this code is supposed to do; if you could explain the actual goal I can maybe give better advice.
The text was updated successfully, but these errors were encountered: