From patchwork Wed Nov 11 10:45:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1398151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gu/RE8nh; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CWLxM1j6Cz9sRR for ; Wed, 11 Nov 2020 21:45:57 +1100 (AEDT) Received: from localhost ([::1]:58102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcndT-0000IR-3u for incoming@patchwork.ozlabs.org; Wed, 11 Nov 2020 05:45:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcnd4-0000Gn-Rm for qemu-devel@nongnu.org; Wed, 11 Nov 2020 05:45:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcnd1-0002Rd-83 for qemu-devel@nongnu.org; Wed, 11 Nov 2020 05:45:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605091525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YJL2qDPkPSwC/qM/FZgbA12Pp2BWT6zkncmJZ48JuMg=; b=gu/RE8nh2d8QqWS1FnC1b6LcB6b+gnJ3yr5BQUVhjfYWYTUnItw/JpjY2+U3Dy2k6Dd0Xg Q7VDNoB1nX0KClEX4fS7lW/au6FEmCCXMzGOOhyszST4gztSsxF6JDv7G7fu3HkVOytZW9 FMylE3kjUbZItpDMSZnIBPEmhPqjkeo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-571-DAPqI47gOPi7r4s756dWow-1; Wed, 11 Nov 2020 05:45:23 -0500 X-MC-Unique: DAPqI47gOPi7r4s756dWow-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C4581084C8B for ; Wed, 11 Nov 2020 10:45:22 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 571FC10027AB; Wed, 11 Nov 2020 10:45:22 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/2] keyval: accept escaped commas in implied option Date: Wed, 11 Nov 2020 05:45:20 -0500 Message-Id: <20201111104521.1179396-2-pbonzini@redhat.com> In-Reply-To: <20201111104521.1179396-1-pbonzini@redhat.com> References: <20201111104521.1179396-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/11 01:49:01 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is used with the weirdly-named device "SUNFD,two", so accepting it is also a preparatory step towards keyval-ifying -device and the device_add monitor command. But in general it is an unexpected wart of the keyval syntax and leads to suboptimal errors compared to QemuOpts: $ ./qemu-system-x86_64 -object foo,,bar,id=obj qemu-system-x86_64: -object foo,,bar,id=obj: invalid object type: foo,bar $ storage-daemon/qemu-storage-daemon --object foo,,bar,id=obj qemu-storage-daemon: Invalid parameter '' To implement this, the flow of the parser is changed to first unescape everything up to the next comma or equal sign. This is done in a new function keyval_fetch_string for both the key and value part. Keys therefore are now parsed in unescaped form, but this makes no difference in practice because a comma is an invalid character for a QAPI name. Thus keys with a comma in them are rejected anyway, as demonstrated by the new testcase. As a side effect of the new code, parse errors are slightly improved as well: "Invalid parameter ''" becomes "Expected parameter before '='" when keyval is fed a string starting with an equal sign. The slightly baroque interface of keyval_fetch_string lets me keep the key parsing loop mostly untouched. It is simplified in the next patch, however. Signed-off-by: Paolo Bonzini --- include/qemu/help_option.h | 11 --- tests/test-keyval.c | 21 +++--- util/keyval.c | 142 ++++++++++++++++++++----------------- 3 files changed, 91 insertions(+), 83 deletions(-) diff --git a/include/qemu/help_option.h b/include/qemu/help_option.h index ca6389a154..328d2a89fd 100644 --- a/include/qemu/help_option.h +++ b/include/qemu/help_option.h @@ -19,15 +19,4 @@ static inline bool is_help_option(const char *s) return !strcmp(s, "?") || !strcmp(s, "help"); } -static inline int starts_with_help_option(const char *s) -{ - if (*s == '?') { - return 1; - } - if (g_str_has_prefix(s, "help")) { - return 4; - } - return 0; -} - #endif diff --git a/tests/test-keyval.c b/tests/test-keyval.c index ee927fe4e4..19f664f535 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -89,6 +89,11 @@ static void test_keyval_parse(void) error_free_or_abort(&err); g_assert(!qdict); + /* Keys must be QAPI identifiers */ + qdict = keyval_parse("weird,,=key", NULL, NULL, &err); + error_free_or_abort(&err); + g_assert(!qdict); + /* Multiple keys, last one wins */ qdict = keyval_parse("a=1,b=2,,x,a=3", NULL, NULL, &error_abort); g_assert_cmpuint(qdict_size(qdict), ==, 2); @@ -178,15 +183,15 @@ static void test_keyval_parse(void) error_free_or_abort(&err); g_assert(!qdict); - /* Likewise (qemu_opts_parse(): implied key with comma value) */ - qdict = keyval_parse(",,,a=1", "implied", NULL, &err); - error_free_or_abort(&err); - g_assert(!qdict); + /* Implied key's value can have a comma */ + qdict = keyval_parse(",,,a=1", "implied", NULL, &error_abort); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, ","); + g_assert_cmpstr(qdict_get_try_str(qdict, "a"), ==, "1"); + qobject_unref(qdict); - /* Implied key's value can't have comma (qemu_opts_parse(): it can) */ - qdict = keyval_parse("val,,ue", "implied", NULL, &err); - error_free_or_abort(&err); - g_assert(!qdict); + qdict = keyval_parse("val,,ue", "implied", NULL, &error_abort); + g_assert_cmpstr(qdict_get_try_str(qdict, "implied"), ==, "val,ue"); + qobject_unref(qdict); /* Empty key is not an implied key */ qdict = keyval_parse("=val", "implied", NULL, &err); diff --git a/util/keyval.c b/util/keyval.c index 7f625ad33c..2213a5fe78 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -16,8 +16,8 @@ * key-vals = [ key-val { ',' key-val } [ ',' ] ] * key-val = key '=' val | help * key = key-fragment { '.' key-fragment } - * key-fragment = / [^=,.]+ / - * val = { / [^,]+ / | ',,' } + * key-fragment = { / [^=,.] / | ',,' } + * val = { / [^,] / | ',,' } * help = 'help' | '?' * * Semantics defined by reduction to JSON: @@ -78,13 +78,13 @@ * Alternative syntax for use with an implied key: * * key-vals = [ key-val-1st { ',' key-val } [ ',' ] ] - * key-val-1st = val-no-key | key-val - * val-no-key = / [^=,]+ / - help + * key-val-1st = (val-no-key - help) | key-val + * val-no-key = { / [^=,] / | ',,' } * * where val-no-key is syntactic sugar for implied-key=val-no-key. * - * Note that you can't use the sugared form when the value contains - * '=' or ','. + * Note that you can't use the sugared form when the value is empty + * or contains '='. */ #include "qemu/osdep.h" @@ -141,7 +141,7 @@ static int key_to_index(const char *key, const char **end) * On failure, store an error through @errp and return NULL. */ static QObject *keyval_parse_put(QDict *cur, - const char *key_in_cur, QString *value, + const char *key_in_cur, const char *value, const char *key, const char *key_cursor, Error **errp) { @@ -152,20 +152,56 @@ static QObject *keyval_parse_put(QDict *cur, if (qobject_type(old) != (value ? QTYPE_QSTRING : QTYPE_QDICT)) { error_setg(errp, "Parameters '%.*s.*' used inconsistently", (int)(key_cursor - key), key); - qobject_unref(value); return NULL; } if (!value) { return old; /* already QDict, do nothing */ } - new = QOBJECT(value); /* replacement */ - } else { - new = value ? QOBJECT(value) : QOBJECT(qdict_new()); } + new = value ? QOBJECT(qstring_from_str(value)) : QOBJECT(qdict_new()); qdict_put_obj(cur, key_in_cur, new); return new; } +/* + * Parse and unescape the string (key or value) pointed to by @start, + * stopping at a single comma or if @key is true an equal sign. + * The string is unescaped and NUL-terminated in place. + * + * On return: + * - either NUL or the separator (comma or equal sign) is returned. + * - the length of the string is stored in @len. + * - @start is advanced to either the NUL or the first character past the + * separator. + */ +static char keyval_fetch_string(char **start, size_t *len, bool key) +{ + char sep; + char *p, *unescaped; + p = unescaped = *start; + for (;;) { + sep = *p; + if (!sep) { + break; + } + if (key && sep == '=') { + ++p; + break; + } + if (sep == ',') { + if (*++p != ',') { + break; + } + } + *unescaped++ = *p++; + } + + *unescaped = 0; + *len = unescaped - *start; + *start = p; + return sep; +} + /* * Parse one parameter from @params. * @@ -179,35 +215,42 @@ static QObject *keyval_parse_put(QDict *cur, * On success, return a pointer to the next parameter, or else to '\0'. * On failure, return NULL. */ -static const char *keyval_parse_one(QDict *qdict, const char *params, - const char *implied_key, bool *help, - Error **errp) +static char *keyval_parse_one(QDict *qdict, char *params, + const char *implied_key, bool *help, + Error **errp) { - const char *key, *key_end, *val_end, *s, *end; + const char *key, *key_end, *s, *end; + const char *val = NULL; + char sep; size_t len; char key_in_cur[128]; QDict *cur; int ret; QObject *next; - QString *val; key = params; - val_end = NULL; - len = strcspn(params, "=,"); - if (len && key[len] != '=') { - if (starts_with_help_option(key) == len) { + sep = keyval_fetch_string(¶ms, &len, true); + if (!len) { + if (sep) { + error_setg(errp, "Expected parameter before '%c'", sep); + } else { + error_setg(errp, "Expected parameter at end of string"); + } + return NULL; + } + if (sep != '=') { + if (is_help_option(key)) { *help = true; - s = key + len; - if (*s == ',') { - s++; - } - return s; + return params; } if (implied_key) { /* Desugar implied key */ + val = key; key = implied_key; - val_end = params + len; len = strlen(implied_key); + } else { + error_setg(errp, "Expected '=' after parameter '%s'", key); + return NULL; } } key_end = key + len; @@ -218,7 +261,7 @@ static const char *keyval_parse_one(QDict *qdict, const char *params, */ cur = qdict; s = key; - for (;;) { + do { /* Want a key index (unless it's first) or a QAPI name */ if (s != key && key_to_index(s, &end) >= 0) { len = end - s; @@ -254,46 +297,16 @@ static const char *keyval_parse_one(QDict *qdict, const char *params, memcpy(key_in_cur, s, len); key_in_cur[len] = 0; s += len; + } while (*s++ == '.'); - if (*s != '.') { - break; - } - s++; - } - - if (key == implied_key) { - assert(!*s); - 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'", - (int)(s - key), key); - return NULL; - } - s++; - - val = qstring_new(); - for (;;) { - if (!*s) { - break; - } else if (*s == ',') { - s++; - if (*s != ',') { - break; - } - } - qstring_append_chr(val, *s++); - } + if (key != implied_key) { + val = params; + keyval_fetch_string(¶ms, &len, false); } - if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) { return NULL; } - return s; + return params; } static char *reassemble_key(GSList *key) @@ -438,10 +451,11 @@ QDict *keyval_parse(const char *params, const char *implied_key, { QDict *qdict = qdict_new(); QObject *listified; - const char *s; + g_autofree char *dup; + char *s; bool help = false; - s = params; + s = dup = g_strdup(params); while (*s) { s = keyval_parse_one(qdict, s, implied_key, &help, errp); if (!s) { From patchwork Wed Nov 11 10:45:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1398152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ddcCP65w; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CWLxM1SY4z9s1l for ; Wed, 11 Nov 2020 21:45:57 +1100 (AEDT) Received: from localhost ([::1]:58072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcndR-0000H7-D8 for incoming@patchwork.ozlabs.org; Wed, 11 Nov 2020 05:45:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcnd3-0000GX-FQ for qemu-devel@nongnu.org; Wed, 11 Nov 2020 05:45:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kcnd1-0002Sw-2i for qemu-devel@nongnu.org; Wed, 11 Nov 2020 05:45:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605091526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2i9ene0FNVfIlw0xpTTbFJBPILtgK2OlbzrxGQ6HE8M=; b=ddcCP65woxYOYw4sQN4UFXbY2nekpbG4X4XSBnpuNZunBQGRziM+cdh8/2K0Fsx6pEPtWm DjBbramypFq2DcUwIRn2vVxUC6s03RjSPrTJB/NscV6DbFnmZtdZfu7iXGz7ggUdXLcdFk xweMAMCZDQ40cI0LGwRecpo4gDJ4/+c= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-gVFKiEj6PciSok0MdMMEbw-1; Wed, 11 Nov 2020 05:45:23 -0500 X-MC-Unique: gVFKiEj6PciSok0MdMMEbw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0713B1084C90 for ; Wed, 11 Nov 2020 10:45:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B701010027AB; Wed, 11 Nov 2020 10:45:22 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/2] keyval: simplify keyval_parse_one Date: Wed, 11 Nov 2020 05:45:21 -0500 Message-Id: <20201111104521.1179396-3-pbonzini@redhat.com> In-Reply-To: <20201111104521.1179396-1-pbonzini@redhat.com> References: <20201111104521.1179396-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/11 01:49:01 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Now that the key is NULL terminated, we can remove some of the contortions that were done to operate on possibly '='-terminated strings in keyval_parse_one. Signed-off-by: Paolo Bonzini --- util/keyval.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/util/keyval.c b/util/keyval.c index 2213a5fe78..76daab0885 100644 --- a/util/keyval.c +++ b/util/keyval.c @@ -170,11 +170,10 @@ static QObject *keyval_parse_put(QDict *cur, * * On return: * - either NUL or the separator (comma or equal sign) is returned. - * - the length of the string is stored in @len. * - @start is advanced to either the NUL or the first character past the * separator. */ -static char keyval_fetch_string(char **start, size_t *len, bool key) +static char keyval_fetch_string(char **start, bool key) { char sep; char *p, *unescaped; @@ -197,7 +196,6 @@ static char keyval_fetch_string(char **start, size_t *len, bool key) } *unescaped = 0; - *len = unescaped - *start; *start = p; return sep; } @@ -219,7 +217,7 @@ static char *keyval_parse_one(QDict *qdict, char *params, const char *implied_key, bool *help, Error **errp) { - const char *key, *key_end, *s, *end; + const char *key, *s, *end; const char *val = NULL; char sep; size_t len; @@ -229,8 +227,8 @@ static char *keyval_parse_one(QDict *qdict, char *params, QObject *next; key = params; - sep = keyval_fetch_string(¶ms, &len, true); - if (!len) { + sep = keyval_fetch_string(¶ms, true); + if (!*key) { if (sep) { error_setg(errp, "Expected parameter before '%c'", sep); } else { @@ -247,13 +245,11 @@ static char *keyval_parse_one(QDict *qdict, char *params, /* Desugar implied key */ val = key; key = implied_key; - len = strlen(implied_key); } else { error_setg(errp, "Expected '=' after parameter '%s'", key); return NULL; } } - key_end = key + len; /* * Loop over key fragments: @s points to current fragment, it @@ -269,24 +265,21 @@ static char *keyval_parse_one(QDict *qdict, char *params, ret = parse_qapi_name(s, false); len = ret < 0 ? 0 : ret; } - assert(s + len <= key_end); - if (!len || (s + len < key_end && s[len] != '.')) { + if (!len || (s[len] != '\0' && s[len] != '.')) { assert(key != implied_key); - error_setg(errp, "Invalid parameter '%.*s'", - (int)(key_end - key), key); + error_setg(errp, "Invalid parameter '%s'", key); return NULL; } if (len >= sizeof(key_in_cur)) { assert(key != implied_key); error_setg(errp, "Parameter%s '%.*s' is too long", - s != key || s + len != key_end ? " fragment" : "", + s != key || s[len] == '.' ? " fragment" : "", (int)len, s); return NULL; } if (s != key) { - next = keyval_parse_put(cur, key_in_cur, NULL, - key, s - 1, errp); + next = keyval_parse_put(cur, key_in_cur, NULL, key, s - 1, errp); if (!next) { return NULL; } @@ -301,9 +294,9 @@ static char *keyval_parse_one(QDict *qdict, char *params, if (key != implied_key) { val = params; - keyval_fetch_string(¶ms, &len, false); + keyval_fetch_string(¶ms, false); } - if (!keyval_parse_put(cur, key_in_cur, val, key, key_end, errp)) { + if (!keyval_parse_put(cur, key_in_cur, val, key, s - 1, errp)) { return NULL; } return params;