]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Ignore bridge template names with multiple printf conversions
authorJán Tomko <jtomko@redhat.com>
Tue, 28 Apr 2015 15:07:20 +0000 (17:07 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 11 May 2015 12:14:33 +0000 (14:14 +0200)
For some reason, we allow a bridge name with %d in it, which we replace
with an unsigned integer to form a bridge name that does not yet exist
on the host.

Do not blindly pass it to virAsprintf if it's not the only conversion,
to prevent crashing on input like:

<network>
  <name>test</name>
  <forward mode='none'/>
  <bridge name='virbr%d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s'/>
</network>

Ignore any template strings that do not have exactly one %d conversion,
like we do in various drivers before calling virNetDevTapCreateInBridgePort.

src/network/bridge_driver.c

index 3b879cd42b460b44747d93bf628f1c5ccd457604..4b5347513eb7887b7d60dc07acbbd4668dc507ef 100644 (file)
@@ -2775,7 +2775,13 @@ networkFindUnusedBridgeName(virNetworkObjListPtr nets,
 
     int ret = -1, id = 0;
     char *newname = NULL;
-    const char *templ = def->bridge ? def->bridge : "virbr%d";
+    const char *templ = "virbr%d";
+    const char *p;
+
+    if (def->bridge &&
+        (p = strchr(def->bridge, '%')) == strrchr(def->bridge, '%') &&
+        p[1] == 'd')
+        templ = def->bridge;
 
     do {
         if (virAsprintf(&newname, templ, id) < 0)