From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
Jan Beulich <JBeulich@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>,
"consulting @ bugseng . com" <consulting@bugseng.com>,
Roberto Bagnara <roberto.bagnara@bugseng.com>,
Federico Serafini <federico.serafini@bugseng.com>,
Nicola Vetrini <nicola.vetrini@bugseng.com>
Subject: Re: [PATCH] xen/efi: Rewrite DOS/PE magic checking without memcmp()
Date: Wed, 17 Apr 2024 09:14:06 +0200 [thread overview]
Message-ID: <Zh92vsPzuHjTIs21@macbook> (raw)
In-Reply-To: <20240416155251.2942504-1-andrew.cooper3@citrix.com>
On Tue, Apr 16, 2024 at 04:52:51PM +0100, Andrew Cooper wrote:
> Misra Rule 21.16 doesn't like the use of memcmp() between a string literal and
> a UINT8 array. Rewrite using plain compares.
The commit message makes it look like it's a type mismatch issue
between the two elements being compared, but from my reading of the
rule the issue is with the usage of a char pointer with memcmp().
IOW: even if the two parameters are char pointers it would still be a
violation.
"Misra Rule 21.16 forbids the use of memcmp() against character
arrays. Rewrite using plain compares since checking for "PE\0\0"
cannot be done using strncmp()."
>
> No functional change.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
LGTM (possibly pending the adjustment of the commit message):
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
One question below to ensure my understating is correct.
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: consulting@bugseng.com <consulting@bugseng.com>
> CC: Roberto Bagnara <roberto.bagnara@bugseng.com>
> CC: Federico Serafini <federico.serafini@bugseng.com>
> CC: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> xen/common/efi/pe.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/xen/common/efi/pe.c b/xen/common/efi/pe.c
> index a84992df9afe..ef8a2543e0a1 100644
> --- a/xen/common/efi/pe.c
> +++ b/xen/common/efi/pe.c
> @@ -111,7 +111,8 @@ const void *__init pe_find_section(const void *image, const UINTN image_size,
> UINTN offset, i;
>
> if ( image_size < sizeof(*dos) ||
> - memcmp(dos->Magic, "MZ", 2) != 0 )
> + dos->Magic[0] != 'M' ||
> + dos->Magic[1] != 'Z' )
For this one you could likely use strncmp()?
> return NULL;
>
> offset = dos->ExeHeader;
> @@ -119,7 +120,10 @@ const void *__init pe_find_section(const void *image, const UINTN image_size,
>
> offset += sizeof(*pe);
> if ( image_size < offset ||
> - memcmp(pe->Magic, "PE\0\0", 4) != 0 )
> + pe->Magic[0] != 'P' ||
> + pe->Magic[1] != 'E' ||
> + pe->Magic[2] != '\0' ||
> + pe->Magic[3] != '\0' )
This one with the double null terminator is indeed not suitable to be
checked using strncmp().
Thanks, Roger.
next prev parent reply other threads:[~2024-04-17 7:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 15:52 [PATCH] xen/efi: Rewrite DOS/PE magic checking without memcmp() Andrew Cooper
2024-04-17 0:28 ` Stefano Stabellini
2024-04-17 7:14 ` Roger Pau Monné [this message]
2024-04-18 11:06 ` Jan Beulich
2024-04-18 16:59 ` Andrew Cooper
2024-04-18 17:31 ` Andrew Cooper
2024-04-18 11:09 ` Jan Beulich
2024-04-18 17:25 ` Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zh92vsPzuHjTIs21@macbook \
--to=roger.pau@citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=consulting@bugseng.com \
--cc=federico.serafini@bugseng.com \
--cc=nicola.vetrini@bugseng.com \
--cc=roberto.bagnara@bugseng.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.