mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-04 20:15:19 +00:00
fdstream: avoid double close bug
Wen Congyang reported that we have a double-close bug if we fail virFDStreamOpenInternal, since childfd duplicated one of the fds[] array contents. In truth, since we always transfer both members of fds to other variables, we should close the fds through those other names, and just use fds[] for pipe(). Bug present since 0.9.0 (commite886237a
). * src/fdstream.c (virFDStreamOpenFileInternal): Swap scope of childfd and fds[], to avoid a double close. (cherry picked from commitf3cfc7c884
)
This commit is contained in:
parent
1ae2604552
commit
bd670db3f0
@ -577,7 +577,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
|
|||||||
int mode)
|
int mode)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
int fds[2] = { -1, -1 };
|
int childfd = -1;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
int errfd = -1;
|
int errfd = -1;
|
||||||
@ -619,7 +619,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
|
|||||||
if ((st->flags & VIR_STREAM_NONBLOCK) &&
|
if ((st->flags & VIR_STREAM_NONBLOCK) &&
|
||||||
(!S_ISCHR(sb.st_mode) &&
|
(!S_ISCHR(sb.st_mode) &&
|
||||||
!S_ISFIFO(sb.st_mode))) {
|
!S_ISFIFO(sb.st_mode))) {
|
||||||
int childfd;
|
int fds[2] = { -1, -1 };
|
||||||
|
|
||||||
if ((oflags & O_ACCMODE) == O_RDWR) {
|
if ((oflags & O_ACCMODE) == O_RDWR) {
|
||||||
streamsReportError(VIR_ERR_INTERNAL_ERROR,
|
streamsReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -665,9 +665,8 @@ virFDStreamOpenFileInternal(virStreamPtr st,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FORCE_CLOSE(fds[0]);
|
|
||||||
VIR_FORCE_CLOSE(fds[1]);
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
VIR_FORCE_CLOSE(childfd);
|
||||||
VIR_FORCE_CLOSE(errfd);
|
VIR_FORCE_CLOSE(errfd);
|
||||||
if (oflags & O_CREAT)
|
if (oflags & O_CREAT)
|
||||||
unlink(path);
|
unlink(path);
|
||||||
|
Loading…
Reference in New Issue
Block a user