From: Alex Jia Date: Sat, 28 Apr 2012 11:01:40 +0000 (+0800) Subject: util: Avoid libvirtd crash in virNetDevTapCreate X-Git-Tag: v0.9.12-rc1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ee18aaa578768893918d67e0dc36fe72b73b736;p=thirdparty%2Flibvirt.git util: Avoid libvirtd crash in virNetDevTapCreate In fact, the 'tapfd' is always NULL, the function 'virNetDevTapCreate()' hasn't assign 'fd' to 'tapfd', when the function 'virNetDevSetMAC()' is failed then goto 'error' label, finally, the VIR_FORCE_CLOSE() will deref a NULL 'tapfd'. * util/virnetdevtap.c (virNetDevTapCreateInBridgePort): fix a NULL pointer derefing. * How to reproduce? $ cat > /tmp/net.xml < test EOF $ virsh net-define /tmp/net.xml $ virsh net-start test error: Failed to start network brTest error: End of file while reading data: Input/output error Signed-off-by: Alex Jia --- diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 0b3ac46183..5d21164c82 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -341,7 +341,8 @@ int virNetDevTapCreateInBridgePort(const char *brname, return 0; error: - VIR_FORCE_CLOSE(*tapfd); + if (tapfd) + VIR_FORCE_CLOSE(*tapfd); return errno; }