From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.85.128.67, mailfrom: philmd@redhat.com) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by groups.io with SMTP; Mon, 15 Apr 2019 10:26:06 -0700 Received: by mail-wm1-f67.google.com with SMTP id z6so458461wmi.0 for ; Mon, 15 Apr 2019 10:26:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DgX3rCZ8wfd34XbhE2I73rUmr9NSeHbeis21SIl0Ris=; b=k3c2osX2UF20jTfClWiz4Exq+A9b9xBoCEK4I1/tfwx/c9jrrn8zcv4SiWIfZaVSlP 4jEf/WJxm91oaLBaCT6Uk/vml3c/FKpewXJuo9b8hz4OvxBN0Zvn1MRb6XSUn+/4/hYG CiE1/MLyPfKV/ngq+0At75m/F3ZrSTrRLxELCzGX0m+XhLEip//f/J1oSiEJxLuTI03x euNyzwZRS5lVHn7Rq6pc9tFeG1FJ+FCdWxn1c3OuP76IUTv2amzZfEP7Kggl+ivHYkVv ovi9pe69E7MwEupZ+HFkVzQTZTxyvUXt7p13lz8scnAqFubq5LWkywOYct6XH56pDtZy emug== X-Gm-Message-State: APjAAAWy3KtnTDhbWtDPOewQvxv8T4avDE8b0fthuLKjNDdLXWsxMZwN Dn6LuTpUit420DyxgccjDPb/avSAqDM= X-Google-Smtp-Source: APXvYqzDIWgxVnMpHGNF7EyTYYyH2fzadRo79OAzgphuvmwEJOB+0RRqLYU3GkIVDb1WRfg64vStMw== X-Received: by 2002:a1c:6783:: with SMTP id b125mr23106040wmc.41.1555349164805; Mon, 15 Apr 2019 10:26:04 -0700 (PDT) Return-Path: Received: from [10.32.224.40] (red-hat-inc.vlan560.asr1.mad1.gblx.net. [159.63.51.90]) by smtp.gmail.com with ESMTPSA id o17sm62787937wrw.73.2019.04.15.10.26.03 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 10:26:04 -0700 (PDT) Subject: Re: [edk2-devel] [PATCH 07/10] OvmfPkg/AcpiPlatformDxe: suppress invalid "deref of undef pointer" warning To: devel@edk2.groups.io, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen References: <20190412233128.4756-1-lersek@redhat.com> <20190412233128.4756-8-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: Date: Mon, 15 Apr 2019 19:26:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190412233128.4756-8-lersek@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 4/13/19 1:31 AM, Laszlo Ersek wrote: > RH covscan emits the following false positive: > >> Error: CLANG_WARNING: >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:182:14: >> warning: Dereference of undefined pointer value >> # Status = FwVol->ReadSection ( >> # ^~~~~~~~~~~~~~~~~~ >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:164:7: note: >> Assuming the condition is false >> # if (QemuDetected ()) { >> # ^~~~~~~~~~~~~~~ >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:164:3: note: >> Taking false branch >> # if (QemuDetected ()) { >> # ^ >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:174:3: note: >> Taking false branch >> # if (EFI_ERROR (Status)) { >> # ^ >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:180:10: note: >> Assuming 'Status' is equal to EFI_SUCCESS >> # while (Status == EFI_SUCCESS) { >> # ^~~~~~~~~~~~~~~~~~~~~ >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:180:3: note: >> Loop condition is true. Entering loop body >> # while (Status == EFI_SUCCESS) { >> # ^ >> edk2-89910a39dcfd/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c:182:14: note: >> Dereference of undefined pointer value >> # Status = FwVol->ReadSection ( >> # ^~~~~~~~~~~~~~~~~~ >> # 180| while (Status == EFI_SUCCESS) { >> # 181| >> # 182|-> Status = FwVol->ReadSection ( >> # 183| FwVol, >> # 184| (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), > > This is invalid because LocateFvInstanceWithTables() sets FwVol on > success. > > Suppress the message by: > - assigning FwVol NULL first (this would replace the original report with > "nullptr deref"), > - asserting that FwVol is no longer NULL, on success. > > What's important here is that ASSERT() ends with ANALYZER_UNREACHABLE() on > failure. > > Cc: Ard Biesheuvel > Cc: Jordan Justen > Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1710 > Issue: scan-0991.txt > Signed-off-by: Laszlo Ersek > --- > OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c > index f2c49953950b..2b529d58a15c 100644 > --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c > +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c > @@ -156,23 +156,30 @@ InstallOvmfFvTables ( > TableHandle = 0; > > if (QemuDetected ()) { > TableInstallFunction = QemuInstallAcpiTable; > } else { > TableInstallFunction = InstallAcpiTable; > } > > + // > + // set FwVol (and use an ASSERT() below) to suppress incorrect > + // compiler/analyzer warnings > + // > + FwVol = NULL; > // > // Locate the firmware volume protocol > // > Status = LocateFvInstanceWithTables (&FwVol); > if (EFI_ERROR (Status)) { > return EFI_ABORTED; > } > + ASSERT (FwVol != NULL); > + > // > // Read tables from the storage file. > // > while (Status == EFI_SUCCESS) { > > Status = FwVol->ReadSection ( > FwVol, > (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile), > Reviewed-by: Philippe Mathieu-Daude