提交 7ab1c25c 编写于 作者: W Wen Congyang

fix crash when starting network

commit 27908453 introduces a regression, and it will
cause libvirt crashed when starting network.

The reason is that tapfd may be NULL, but we dereference
it without checking whether it is NULL.
上级 97656536
...@@ -484,7 +484,8 @@ brAddTap(brControl *ctl, ...@@ -484,7 +484,8 @@ brAddTap(brControl *ctl,
errno = brCreateTap(ctl, ifname, vnet_hdr, tapfd); errno = brCreateTap(ctl, ifname, vnet_hdr, tapfd);
if (*tapfd < 0 || errno) /* fd has been closed in brCreateTap() when it failed. */
if (errno)
goto error; goto error;
/* We need to set the interface MAC before adding it /* We need to set the interface MAC before adding it
...@@ -494,22 +495,23 @@ brAddTap(brControl *ctl, ...@@ -494,22 +495,23 @@ brAddTap(brControl *ctl,
* device before we set our static MAC. * device before we set our static MAC.
*/ */
if ((errno = brSetInterfaceMac(ctl, *ifname, macaddr))) if ((errno = brSetInterfaceMac(ctl, *ifname, macaddr)))
goto error; goto close_fd;
/* We need to set the interface MTU before adding it /* We need to set the interface MTU before adding it
* to the bridge, because the bridge will have its * to the bridge, because the bridge will have its
* MTU adjusted automatically when we add the new interface. * MTU adjusted automatically when we add the new interface.
*/ */
if ((errno = brSetInterfaceMtu(ctl, bridge, *ifname))) if ((errno = brSetInterfaceMtu(ctl, bridge, *ifname)))
goto error; goto close_fd;
if ((errno = brAddInterface(ctl, bridge, *ifname))) if ((errno = brAddInterface(ctl, bridge, *ifname)))
goto error; goto close_fd;
if (up && ((errno = brSetInterfaceUp(ctl, *ifname, 1)))) if (up && ((errno = brSetInterfaceUp(ctl, *ifname, 1))))
goto error; goto close_fd;
return 0; return 0;
error: close_fd:
VIR_FORCE_CLOSE(*tapfd); if (tapfd)
VIR_FORCE_CLOSE(*tapfd);
error:
return errno; return errno;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册