From nobody Sat May 11 04:16:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153053122446065.85440451681575; Mon, 2 Jul 2018 04:33:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBC8430820CD; Mon, 2 Jul 2018 11:33:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8AAB25DD72; Mon, 2 Jul 2018 11:33:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 662973D3BC; Mon, 2 Jul 2018 11:33:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w62BXchN017323 for ; Mon, 2 Jul 2018 07:33:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FD8017D6C; Mon, 2 Jul 2018 11:33:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 326EF5DD82 for ; Mon, 2 Jul 2018 11:33:35 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B879F3082A42 for ; Mon, 2 Jul 2018 11:33:33 +0000 (UTC) Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=dim-vz7.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fZx5G-0004Ba-Hy for libvir-list@redhat.com; Mon, 02 Jul 2018 14:33:30 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Mon, 2 Jul 2018 14:33:29 +0300 Message-Id: <1530531209-869250-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Sender passed SPF test, ACL 227 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 02 Jul 2018 11:33:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 02 Jul 2018 11:33:34 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] util: set OOM in virCopyLastError if error is not set X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 02 Jul 2018 11:33:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virCopyLastError is intended to be used after last error is set. However due to virLastErrorObject failures (very unlikely through as thread local error is allocated on first use) we can have zero fields in a copy as a result. In particular code field can be set to VIR_ERR_OK. In some places (qemu monitor, qemu agent and qemu migaration code for example) we use copy result as a flag and this leads to bugs. Let's set OOM-like error in copy in case of virLastErrorObject failures. Signed-off-by: Nikolay Shirokovskiy Reviewed-by: John Ferlan --- Changes from v1: - check @to - set OMM error instead of using virErrorGenericFailure src/util/virerror.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/util/virerror.c b/src/util/virerror.c index f198f27..737ea92 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -366,19 +366,25 @@ virSetError(virErrorPtr newerr) * * One will need to free the result with virResetError() * - * Returns 0 if no error was found and the error code otherwise and -1 in = case - * of parameter error. + * Returns error code or -1 in case of parameter error. */ int virCopyLastError(virErrorPtr to) { virErrorPtr err =3D virLastErrorObject(); + + if (!to) + return -1; + /* We can't guarantee caller has initialized it to zero */ memset(to, 0, sizeof(*to)); - if (err) + if (err) { virCopyError(err, to); - else - virResetError(to); + } else { + to->code =3D VIR_ERR_NO_MEMORY; + to->domain =3D VIR_FROM_NONE; + to->level =3D VIR_ERR_ERROR; + } return to->code; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list