summaryrefslogtreecommitdiff
path: root/util/keyval.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2020-10-11 09:35:01 +0200
committerKevin Wolf <kwolf@redhat.com>2020-10-15 16:06:27 +0200
commit7051ae6cf1ec1072d2cdaa978660b22245a1efad (patch)
tree6c49414624148390bf01f3735d5b33b37e5f1106 /util/keyval.c
parentce40cbf11d215dc3f820bf32937f7e44aab4a1e3 (diff)
downloadqemu-7051ae6cf1ec1072d2cdaa978660b22245a1efad.zip
keyval: Fix parsing of ',' in value of implied key
The previous commit demonstrated documentation and code disagree on parsing of ',' in the value of an implied key. Fix the code to match the documentation. This breaks uses of keyval_parse() that pass an implied key and accept a value containing ','. None of the existing uses does: * audiodev: implied key "driver" is enum AudiodevDriver, none of the values contains ',' * display: implied key "type" is enum DisplayType, none of the values contains ',' * blockdev: implied key "driver is enum BlockdevDriver, none of the values contains ',' * export: implied key "type" is enum BlockExportType, none of the values contains ',' * monitor: implied key "mode" is enum MonitorMode, none of the values contains ',' * nbd-server: no implied key. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20201011073505.1185335-4-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'util/keyval.c')
-rw-r--r--util/keyval.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/util/keyval.c b/util/keyval.c
index 82d8497c71..8f33a36a7c 100644
--- a/util/keyval.c
+++ b/util/keyval.c
@@ -173,7 +173,7 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
const char *implied_key,
Error **errp)
{
- const char *key, *key_end, *s, *end;
+ const char *key, *key_end, *val_end, *s, *end;
size_t len;
char key_in_cur[128];
QDict *cur;
@@ -182,10 +182,12 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
QString *val;
key = params;
+ val_end = NULL;
len = strcspn(params, "=,");
if (implied_key && len && key[len] != '=') {
/* Desugar implied key */
key = implied_key;
+ val_end = params + len;
len = strlen(implied_key);
}
key_end = key + len;
@@ -241,7 +243,11 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
if (key == implied_key) {
assert(!*s);
- s = params;
+ val = qstring_from_substr(params, 0, val_end - params);
+ s = val_end;
+ if (*s == ',') {
+ s++;
+ }
} else {
if (*s != '=') {
error_setg(errp, "Expected '=' after parameter '%.*s'",
@@ -249,19 +255,19 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
return NULL;
}
s++;
- }
- val = qstring_new();
- for (;;) {
- if (!*s) {
- break;
- } else if (*s == ',') {
- s++;
- if (*s != ',') {
+ val = qstring_new();
+ for (;;) {
+ if (!*s) {
break;
+ } else if (*s == ',') {
+ s++;
+ if (*s != ',') {
+ break;
+ }
}
+ qstring_append_chr(val, *s++);
}
- qstring_append_chr(val, *s++);
}
if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) {