mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 11:50:29 +01:00
core: don't close input fd in nm_utils_fd_get_contents()
The function should not close the input file descriptor; however
fdopen() associates the fd to the new stream so that when the stream
is closed, the fd is too. The result is a double close() and the
second call can in certain cases affect a wrong fd.
Use a duplicate fd for the stream.
Fixes: 1d9bdad1df
https://bugzilla.redhat.com/show_bug.cgi?id=1451236
This commit is contained in:
parent
d1a58fbfbf
commit
597072296a
1 changed files with 8 additions and 1 deletions
|
|
@ -2793,9 +2793,16 @@ nm_utils_fd_get_contents (int fd,
|
|||
nm_auto_fclose FILE *f = NULL;
|
||||
char buf[4096];
|
||||
gsize n_have, n_alloc;
|
||||
int fd2;
|
||||
|
||||
if (!(f = fdopen (fd, "r")))
|
||||
fd2 = dup (fd);
|
||||
if (fd2 < 0)
|
||||
return _get_contents_error (error, 0, "error during dup");
|
||||
|
||||
if (!(f = fdopen (fd2, "r"))) {
|
||||
close (fd2);
|
||||
return _get_contents_error (error, 0, "failure during fdopen");
|
||||
}
|
||||
|
||||
n_have = 0;
|
||||
n_alloc = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue