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; Tue, 23 Apr 2019 01:01:00 -0700 Received: by mail-wm1-f67.google.com with SMTP id c1so17377896wml.4 for ; Tue, 23 Apr 2019 01:00:59 -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=Cibo1iW99DH2kU/zogDQFcILCF3sPaKel1B6dkzwGaI=; b=IyjbsKswCZ71/tUTU+6rIgw9GE1PEcsLnhGbogZWJ1jD8OVuId+m7TjxH3uQhUzVNr kX5hd8M1gv0nNLveMIdqmc9VCzJiZrqiTnTreVkyTf3lL4F0pYjpH3FR26sR1aQLCJYR yYn9x8QypGi1OYldgh9cueo8441ccKEV+JYdlZXXqicanlIRxV0ITWoB5Q9E+DO/rLkk WGyKcqsV4cge0RQ3FIPvRveT7eycJUd6EKj+KbTb5rvcMHVmts6yrSzWJQu4RZdpL8Ea zMZ5oBbLJMjVXC1vJfpH3EflQdsz9H5di5Ogo8lFPI5oqZ3hk75NA6l1dYgu3eqzcxh/ L4wQ== X-Gm-Message-State: APjAAAW3hoYuG1sldV6pyaX/eKptH6Jgu08moMA2QEEfpR6VITKSAkcv xZjAiWHBziqST81BkuixsfQFAX8Jdke8aQ== X-Google-Smtp-Source: APXvYqxwGR0Y55dD29eEHrQfUlED9WrqnVagxdeLpdJzNHf9uA0FFnfSR0oIFA+He/eI8Coxg80YSg== X-Received: by 2002:a05:600c:21c3:: with SMTP id x3mr1192609wmj.90.1556006458462; Tue, 23 Apr 2019 01:00:58 -0700 (PDT) Return-Path: Received: from [192.168.1.25] (atoulouse-656-1-803-163.w86-221.abo.wanadoo.fr. [86.221.12.163]) by smtp.gmail.com with ESMTPSA id v184sm23847028wma.6.2019.04.23.01.00.55 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 23 Apr 2019 01:00:57 -0700 (PDT) Subject: Re: [edk2-devel] [PATCH v2 4/5] MdePkg/PiFirmwareFile: fix undefined behavior in FFS_FILE_SIZE To: devel@edk2.groups.io, lersek@redhat.com Cc: Liming Gao , Michael D Kinney References: <20190418174710.12236-1-lersek@redhat.com> <20190418174710.12236-5-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: Tue, 23 Apr 2019 10:00:52 +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: <20190418174710.12236-5-lersek@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 4/18/19 7:47 PM, Laszlo Ersek wrote: > Accessing "EFI_FFS_FILE_HEADER.Size", which is of type UINT8[3], through a > (UINT32*), is undefined behavior. Fix it by accessing the array elements > individually. > > Cc: Liming Gao > Cc: Michael D Kinney > Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1710 > Signed-off-by: Laszlo Ersek > --- > > Notes: > v2: > > - eliminate intermediate macros [Mike] > > MdePkg/Include/Pi/PiFirmwareFile.h | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/MdePkg/Include/Pi/PiFirmwareFile.h b/MdePkg/Include/Pi/PiFirmwareFile.h > index 05470538de42..ec7729e9c36e 100644 > --- a/MdePkg/Include/Pi/PiFirmwareFile.h > +++ b/MdePkg/Include/Pi/PiFirmwareFile.h > @@ -179,8 +179,15 @@ typedef struct { > #define IS_FFS_FILE2(FfsFileHeaderPtr) \ > (((((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Attributes) & FFS_ATTRIB_LARGE_FILE) == FFS_ATTRIB_LARGE_FILE) > > -#define FFS_FILE_SIZE(FfsFileHeaderPtr) \ > - ((UINT32) (*((UINT32 *) ((EFI_FFS_FILE_HEADER *) (UINTN) FfsFileHeaderPtr)->Size) & 0x00ffffff)) > +/// > +/// The argument passed as the FfsFileHeaderPtr parameter to the > +/// FFS_FILE_SIZE() function-like macro below must not have side effects: > +/// FfsFileHeaderPtr is evaluated multiple times. > +/// > +#define FFS_FILE_SIZE(FfsFileHeaderPtr) ((UINT32) ( \ > + (((EFI_FFS_FILE_HEADER *) (UINTN) (FfsFileHeaderPtr))->Size[0] ) | \ > + (((EFI_FFS_FILE_HEADER *) (UINTN) (FfsFileHeaderPtr))->Size[1] << 8) | \ > + (((EFI_FFS_FILE_HEADER *) (UINTN) (FfsFileHeaderPtr))->Size[2] << 16))) > > #define FFS_FILE2_SIZE(FfsFileHeaderPtr) \ > ((UINT32) (((EFI_FFS_FILE_HEADER2 *) (UINTN) FfsFileHeaderPtr)->ExtendedSize)) > Reviewed-by: Philippe Mathieu-Daude