]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Validate the bios_date format for <sysinfo>
authorJohn Ferlan <jferlan@redhat.com>
Fri, 26 Apr 2013 12:33:26 +0000 (08:33 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 15 May 2013 16:05:22 +0000 (12:05 -0400)
Add incorrectly formatted bios_date validation test

src/conf/domain_conf.c
tests/qemuxml2argvdata/qemuxml2argv-smbios-date.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index 472b4b406eb0af7907b507e15e8908a3594c16fd..81560b8f5f2dad33a4b6cf71390a1596f1147421 100644 (file)
@@ -8465,6 +8465,29 @@ virSysinfoParseXML(const xmlNodePtr node,
         virXPathString("string(bios/entry[@name='version'])", ctxt);
     def->bios_date =
         virXPathString("string(bios/entry[@name='date'])", ctxt);
+    if (def->bios_date != NULL) {
+        char *ptr;
+        int month, day, year;
+
+        /* Validate just the format of the date
+         * Expect mm/dd/yyyy or mm/dd/yy,
+         * where yy must be 00->99 and would be assumed to be 19xx
+         * a yyyy date should be 1900 and beyond
+         */
+        if (virStrToLong_i(def->bios_date, &ptr, 10, &month) < 0 ||
+            *ptr != '/' ||
+            virStrToLong_i(ptr + 1, &ptr, 10, &day) < 0 ||
+            *ptr != '/' ||
+            virStrToLong_i(ptr + 1, &ptr, 10, &year) < 0 ||
+            *ptr != '\0' ||
+            (month < 1 || month > 12) ||
+            (day < 1 || day > 31) ||
+            (year < 0 || (year >= 100 && year < 1900))) {
+            virReportError(VIR_ERR_XML_DETAIL, "%s",
+                           _("Invalid BIOS 'date' format"));
+            goto error;
+        }
+    }
     def->bios_release =
         virXPathString("string(bios/entry[@name='release'])", ctxt);
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smbios-date.xml b/tests/qemuxml2argvdata/qemuxml2argv-smbios-date.xml
new file mode 100644 (file)
index 0000000..7b2f33a
--- /dev/null
@@ -0,0 +1,23 @@
+<domain type='qemu'>
+  <name>smbios</name>
+  <uuid>362d1fc1-df7d-193e-5c18-49a71bd1da66</uuid>
+  <memory unit='KiB'>1048576</memory>
+  <currentMemory unit='KiB'>1048576</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <smbios mode="sysinfo"/>
+  </os>
+  <sysinfo type="smbios">
+    <bios>
+      <entry name="date">999/999/123</entry>
+    </bios>
+  </sysinfo>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+  </devices>
+</domain>
index ac31d2a9807641ccfccfda31b7a9a9047fb3b7a6..58aeddde29cb8442c3eaba189ea34502db0bb5f8 100644 (file)
@@ -825,6 +825,7 @@ mymain(void)
 
 
     DO_TEST("smbios", QEMU_CAPS_SMBIOS_TYPE);
+    DO_TEST_PARSE_ERROR("smbios-date", QEMU_CAPS_SMBIOS_TYPE);
 
     DO_TEST("watchdog", NONE);
     DO_TEST("watchdog-device", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);