mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 15:10:14 +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:1d9bdad1dfhttps://bugzilla.redhat.com/show_bug.cgi?id=1451236 (cherry picked from commit597072296a)
This commit is contained in:
parent
bb4b6be912
commit
01b10fe24d
1 changed files with 8 additions and 1 deletions
|
|
@ -2933,9 +2933,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