Skip to contentSkip to conversation

qemu-option: Reject anti-social IDs

PATCH Applied Markus Armbruster 3 participants 3 messages Jun 8, 2010 – Jun 22, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-option: Reject anti-social IDs

Restrict IDs to letters, digits, '-', '.', '_', starting with a letter.

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

---
 qemu-option.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
qemu-option.c +20 -0
index acd74f9..74fb882 100644
@@ -672,11 +672,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) {
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 7 lines · Markus Armbruster

Restrict IDs to letters, digits, '-', '.', '_', starting with a letter.

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

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 41 lines
---
  qemu-option.c |   20 ++++++++++++++++++++
  1 files changed, 20 insertions(+), 0 deletions(-)
qemu-option.c +20 -0
index acd74f9..74fb882 100644
@@ -672,11 +672,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) {
#2 lore raw
In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster

Restrict IDs to letters, digits, '-', '.', '_', starting with a letter.

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

Broke autotest (used leading numeric char). Patch posted.

Signature · 1 line
error compiling committee.c: too many arguments to function