]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
command: avoid double close bugs
authorEric Blake <eblake@redhat.com>
Tue, 29 May 2012 23:47:58 +0000 (17:47 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 31 May 2012 03:41:45 +0000 (21:41 -0600)
commitda831afcf2f6c0d3ed1ea3128a6208f548a05d8f
treefa03a21637ff87472a5f1273ffe1fac40922e4da
parent655cffa0f25be40c68624036af80bde102177612
command: avoid double close bugs

KAMEZAWA Hiroyuki reported a nasty double-free bug when virCommand
is used to convert a string into input to a child command.  The
problem is that the poll() loop of virCommandProcessIO would close()
the write end of the pipe in order to let the child see EOF, then
the caller virCommandRun() would also close the same fd number, with
the second close possibly nuking an fd opened by some other thread
in the meantime.  This in turn can have all sorts of bad effects.

The bug has been present since the introduction of virCommand in
commit f16ad06f.

This is based on his first attempt at a patch, at
https://bugzilla.redhat.com/show_bug.cgi?id=823716

* src/util/command.c (_virCommand): Drop inpipe member.
(virCommandProcessIO): Add argument, to avoid closing caller's fd
without informing caller.
(virCommandRun, virCommandNewArgs): Adjust clients.
src/util/command.c