]> xenbits.xensource.com Git - xen.git/commitdiff
xen/efi: Rewrite DOS/PE magic checking without memcmp()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 16 Apr 2024 15:21:34 +0000 (16:21 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 18 Apr 2024 19:43:11 +0000 (20:43 +0100)
Misra Rule 21.16 doesn't like the use of memcmp() against character arrays (a
string literal in this case).  This is a rare piece of logic where we're
looking for a magic marker that just happens to make sense when expressed as
ASCII.  Rewrite using plain compares.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/efi/pe.c

index a84992df9afea47c82a3af80ece4005c54c998af..ef8a2543e0a14271b573780a2a7cba05a598c9b6 100644 (file)
@@ -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' )
         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' )
         return NULL;
 
     if ( pe->FileHeader.Machine != PE_HEADER_MACHINE )