From nobody Mon Nov 25 00:16:03 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1720258227; cv=none; d=zohomail.com; s=zohoarc; b=d1cZhXt9s4J/r/8kgBaEgBUCunzWx8dSRDRiSUSlNIaj55+7XpbdXfONY3n+ytPhR6K1zDEvLxYohBjJob1KGPr8gw95h0Y6bZZ6H0p8g4NPMRPS8MrmW5S5F4N5K9EI9itPPvA8JFafZ7Ao3ZjdHjRwJCqHGqrw6xrggDOkzf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720258227; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jiaYdGJdtPWsnfbPGe8XqhPOhb333O5wAJMSGqRo6p4=; b=KeP1C7xJfwdfaCMyh+37f7VViGcTPTTDximGllC7hOVQB7EpgXU7ah9Z0XrMu73LEm1XxBLKQAcXi56oe4j2ktWbgg3ApVmKcqp80MUkNTPWB+fiUUwurIxi+7uVcuyxpWy0ESjnjpyl4E9YPPOmu7jTCtS56LqGkmc4dA1+T08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720258227897481.99258597621485; Sat, 6 Jul 2024 02:30:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQ1jk-0008Rv-0d; Sat, 06 Jul 2024 05:29:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sQ1jg-0008Pj-Un for qemu-devel@nongnu.org; Sat, 06 Jul 2024 05:29:42 -0400 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQ1jf-0006oz-CN for qemu-devel@nongnu.org; Sat, 06 Jul 2024 05:29:40 -0400 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3d928b2843dso32378b6e.2 for ; Sat, 06 Jul 2024 02:29:39 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70b01193a96sm4346393b3a.31.2024.07.06.02.29.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Jul 2024 02:29:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720258178; x=1720862978; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jiaYdGJdtPWsnfbPGe8XqhPOhb333O5wAJMSGqRo6p4=; b=FvcRwOdH+8skz6pW0F2TFm6R/EDBg7WI2160t05D5u4H4+rOlepjqp1eYvjAJ3ewL5 mO7HBZnugCeNohwAceIAhL61vDG27PwgVBn5Ipqmrerlzx5t18rp8pKspfzoV602BCJc x9gJ+ab8V8shk8JzwtEEi8ZvAK6OnBomY8+oxiDKRDZdH5lu9qOw7e3DlEYv4wD8Yvha DaVbw++vP3obHtu+tkpgOJcoV1RzeFmMlupbPh1aBYDC93IveJ+sH3z6qrhqK6h45jrc EUvQ8jLfdd1TxXKJl02Ya5C/Is7KN9cJf0sk5pUiXWywVD7gloTeH2WlRoqr8wA6ku+E INmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720258178; x=1720862978; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jiaYdGJdtPWsnfbPGe8XqhPOhb333O5wAJMSGqRo6p4=; b=auTfE55RkmMS84sonXWirlC63sr/UE+OlTiLgQNAeOJM0/yJF2jXjh9TKYb7Y9DLYH qG8h4JjP9mlraxM3DIybRl8IoUDmoHpzGqm0cpcBNgOmLRyoA72HbNIIkdBMejAEdKG1 AqmkoqVlHdfPrYf/RjQkSCuMBZ3q65Ta/uA0c53NQy63pu1EzrMs5eVZVyOfXPPZqKTf BjBftustfol4CQl2yt3vVuE+uiK4OLXRGaIUPyoTpYXLlHpl92IN6QoROmyWSCK3f3lb 4yvipr20ppxN+TYIXQjvMQF0qf9iwepEwtfI/JPpsdGFuZs6F+VGEAGGTKW4KCXrKdbB lGpg== X-Gm-Message-State: AOJu0YyzAAgZl3K07G+a83rzGsdPdDQxBjf1De9Hy45jbrz9Fx1JSYx+ TtdGoOKXhko+qmYfjzvCq4/rUsPlT72t1TH71FSwGMqRUeXMhFux1JsvtcWulNK6GuGAqYuHHAl vZ24= X-Google-Smtp-Source: AGHT+IF9neLvPkPJVUwqJamV3WTms4iS9iN6pwgUA2PkCasSKHD3PtXsqcmsJEyRDzQtLpwRbid1zg== X-Received: by 2002:a05:6808:19a7:b0:3d6:2fb8:2905 with SMTP id 5614622812f47-3d914cb4c7amr7416107b6e.42.1720258178266; Sat, 06 Jul 2024 02:29:38 -0700 (PDT) From: Akihiko Odaki Date: Sat, 06 Jul 2024 18:29:22 +0900 Subject: [PATCH 2/4] qapi: Do not consume a value when visit_type_enum() fails MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240706-rombar-v1-2-802daef2aec1@daynix.com> References: <20240706-rombar-v1-0-802daef2aec1@daynix.com> In-Reply-To: <20240706-rombar-v1-0-802daef2aec1@daynix.com> To: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Marcel Apfelbaum , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Sriram Yagnaraman , Jason Wang , Keith Busch , Klaus Jensen , Markus Armbruster Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::229; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x229.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1720258229283100003 Consuming a value when visit_type_enum() fails makes it impossible to reinterpret the value with a different type. Signed-off-by: Akihiko Odaki --- include/qapi/visitor.h | 5 ----- qapi/opts-visitor.c | 5 ----- qapi/qapi-visit-core.c | 4 +++- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index b3ae3188edfb..8e841b26428b 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -513,11 +513,6 @@ void visit_set_policy(Visitor *v, CompatPolicy *policy= ); * is an input visitor. * * Return true on success, false on failure. - * - * May call visit_type_str() under the hood, and the enum visit may - * fail even if the corresponding string visit succeeded; this implies - * that an input visitor's visit_type_str() must have no unwelcome - * side effects. */ bool visit_type_enum(Visitor *v, const char *name, int *obj, const QEnumLookup *lookup, Error **errp); diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index e9fad756e189..d83434b95a56 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -359,11 +359,6 @@ opts_type_str(Visitor *v, const char *name, char **obj= , bool consume, return false; } *obj =3D g_strdup(opt->str ? opt->str : ""); - /* Note that we consume a string even if this is called as part of - * an enum visit that later fails because the string is not a - * valid enum value; this is harmless because tracking what gets - * consumed only matters to visit_end_struct() as the final error - * check if there were no other failures during the visit. */ if (consume) { processed(ov, name); } diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 89b52fc99202..1137d472290b 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -411,7 +411,7 @@ static bool input_type_enum(Visitor *v, const char *nam= e, int *obj, int64_t value; g_autofree char *enum_str =3D NULL; =20 - if (!visit_type_str(v, name, &enum_str, errp)) { + if (!visit_type_str_preserving(v, name, &enum_str, errp)) { return false; } =20 @@ -430,6 +430,8 @@ static bool input_type_enum(Visitor *v, const char *nam= e, int *obj, return false; } =20 + enum_str =3D NULL; + visit_type_str(v, name, &enum_str, &error_abort); *obj =3D value; return true; } --=20 2.45.2