]> git.proxmox.com Git - qemu.git/commitdiff
qemu-option: Reject anti-social IDs
authorMarkus Armbruster <armbru@redhat.com>
Tue, 8 Jun 2010 11:54:26 +0000 (13:54 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 14 Jun 2010 20:46:28 +0000 (15:46 -0500)
Restrict IDs to letters, digits, '-', '.', '_', starting with a
letter.

This takes care of '/' in qdev IDs breaking qbus_find().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
qemu-option.c

index f88486580cdd6cd406d1d0fc390874b6df8e3bad..7f70d0f5fb6d7c9375ee3a74fd659cd9f5877fee 100644 (file)
@@ -673,11 +673,31 @@ QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id)
     return NULL;
 }
 
+static int id_wellformed(const char *id)
+{
+    int i;
+
+    if (!qemu_isalpha(id[0])) {
+        return 0;
+    }
+    for (i = 1; id[i]; i++) {
+        if (!qemu_isalnum(id[i]) && !strchr("-._", id[i])) {
+            return 0;
+        }
+    }
+    return 1;
+}
+
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists)
 {
     QemuOpts *opts = NULL;
 
     if (id) {
+        if (!id_wellformed(id)) {
+            qerror_report(QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
+            error_printf_unless_qmp("Identifiers consist of letters, digits, '-', '.', '_', starting with a letter.\n");
+            return NULL;
+        }
         opts = qemu_opts_find(list, id);
         if (opts != NULL) {
             if (fail_if_exists) {