Skip to content

error: Do compile-time format string checking on grub>

Glenn Washburn grub-devel 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest14 patches 5 repliesIn review
  2. v513 patches 2 repliesSuperseded
  3. v413 patches 12 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v22 patches2 repliesSuperseded
v11 patch0 repliesSuperseded

Changes in v6 from the cover letter

* Fix formatting issues with spaces around format string macros and casts
* Add extra patch #14 which is the better fix for #12, but needs more testing

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14misc: Format string for grub_error should be a literalgrub-core/loader/efi/chainloader.c grub-core/net/tftp.c grub-core/script/lexer.c+3 -30 replies
2/14error: grub_error missing format string argumentgrub-core/parttool/msdospart.c+2 -20 replies
3/14error: grub_error format string add missing format codegrub-core/video/bochs.c+2 -20 replies
4/14dmraid_nvidia: Format string error in grub_errorgrub-core/disk/dmraid_nvidia.c+1 -10 replies
5/14grub_error: Use format code PRIuGRUB_SIZE for variables of type grub_size_tgrub-core/disk/cryptodisk.c grub-core/kern/efi/efi.c grub-core/loader/efi/chainloader.c +1 more+12 -70 replies
6/14pgp: Format code for grub_error is incorrectgrub-core/commands/pgp.c+2 -20 replies
7/14efi: Format string error in grub_errorgrub-core/kern/efi/mm.c+3 -20 replies
8/14error: Use PRI* macros to get correct format string code across architecturesgrub-core/loader/i386/pc/linux.c+4 -30 replies
9/14error: Use format code PRIxGRUB_UINT64_T for 64-bit uint argument in grub_errorgrub-core/disk/ata.c+6 -40 replies
10/14error: Use format code PRIxGRUB_UINT64_T for 64-bit arg in grub_errorgrub-core/efiemu/i386/loadcore64.c grub-core/kern/arm64/dl.c grub-core/kern/ia64/dl.c +3 more+13 -70 replies
11/14error: Use format code PRIuGRUB_UINT64_T for 64-bit typed fileblock in grub_errorgrub-core/fs/hfsplus.c+2 -10 replies
12/14error: Use format code llu for 64-bit uint bp->blk_prop in grub_errorgrub-core/fs/zfs/zfs.c+2 -20 replies
13/14error: Do compile-time format string checking on grub_errorinclude/grub/err.h+2 -10 replies
14/14zfs: Use grub_uint64_t instead of 1ULL in BF64_*CODE macrosgrub-core/fs/zfs/zfs.c include/grub/zfs/spa.h+5 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.

Read the v6 thread

Cover letter [PATCH v6 00/14] error: Do compile-time format string checking on grub>

Daniel, you mentioned wanting a separate patch series which is the real fix for patch #12. I've added it to this patch series, since they go together. I can send the single patch as a separate thread if that still desirable.

Changes since v5
* Fix formatting issues with spaces around format string macros and casts
* Add extra patch #14 which is the better fix for #12, but needs more testing

Glenn

Glenn Washburn (14):
misc: Format string for grub_error should be a literal
error: grub_error missing format string argument
error: grub_error format string add missing format code
dmraid_nvidia: Format string error in grub_error
grub_error: Use format code PRIuGRUB_SIZE for variables of type
grub_size_t
pgp: Format code for grub_error is incorrect
efi: Format string error in grub_error
error: Use PRI* macros to get correct format string code across
architectures
error: Use format code PRIxGRUB_UINT64_T for 64-bit uint argument in
grub_error
error: Use format code PRIxGRUB_UINT64_T for 64-bit arg in grub_error
error: Use format code PRIuGRUB_UINT64_T for 64-bit typed fileblock in
grub_error
error: Use format code llu for 64-bit uint bp->blk_prop in grub_error
error: Do compile-time format string checking on grub_error
zfs: Use grub_uint64_t instead of 1ULL in BF64_*CODE macros

 grub-core/commands/pgp.c           |  4 ++--
 grub-core/disk/ata.c               | 10 ++++++----
 grub-core/disk/cryptodisk.c        | 12 ++++++++----
 grub-core/disk/dmraid_nvidia.c     |  2 +-
 grub-core/efiemu/i386/loadcore64.c |  3 ++-
 grub-core/fs/hfsplus.c             |  3 ++-
 grub-core/fs/zfs/zfs.c             |  3 ++-
 grub-core/kern/arm64/dl.c          |  3 ++-
 grub-core/kern/efi/efi.c           |  2 +-
 grub-core/kern/efi/mm.c            |  5 +++--
 grub-core/kern/ia64/dl.c           |  3 ++-
 grub-core/kern/riscv/dl.c          |  5 +++--
 grub-core/kern/sparc64/dl.c        |  3 ++-
 grub-core/kern/x86_64/dl.c         |  3 ++-
 grub-core/loader/efi/chainloader.c |  4 ++--
 grub-core/loader/i386/bsd.c        |  3 ++-
 grub-core/loader/i386/pc/linux.c   |  7 ++++---
 grub-core/net/tftp.c               |  2 +-
 grub-core/parttool/msdospart.c     |  4 ++--
 grub-core/script/lexer.c           |  2 +-
 grub-core/video/bochs.c            |  4 ++--
 include/grub/err.h                 |  3 ++-
 include/grub/zfs/spa.h             |  4 ++--
 23 files changed, 56 insertions(+), 38 deletions(-)

Range-diff against v5:
1: f34399c63 ! 1: 0f35c04e3 grub_error: Use format code PRIuGRUB_SIZE for variables of type grub_size_t

    @@ grub-core/disk/cryptodisk.c: grub_cryptodisk_setcipher (grub_cryptodisk_t crypt,
      	{
     -	  ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d",
     +	  ret = grub_error (GRUB_ERR_BAD_ARGUMENT,
    -+			    "Unsupported XTS block size: %"PRIuGRUB_SIZE,
    ++			    "Unsupported XTS block size: %" PRIuGRUB_SIZE,
      			    cipher->cipher->blocksize);
      	  goto err;
      	}
    @@ grub-core/disk/cryptodisk.c: grub_cryptodisk_setcipher (grub_cryptodisk_t crypt,
      	{
     -	  ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d",
     +	  ret = grub_error (GRUB_ERR_BAD_ARGUMENT,
    -+			    "Unsupported XTS block size: %"PRIuGRUB_SIZE,
    ++			    "Unsupported XTS block size: %" PRIuGRUB_SIZE,
      			    secondary_cipher->cipher->blocksize);
      	  goto err;
      	}
    @@ grub-core/disk/cryptodisk.c: grub_cryptodisk_setcipher (grub_cryptodisk_t crypt,
      	{
     -	  ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d",
     +	  ret = grub_error (GRUB_ERR_BAD_ARGUMENT,
    -+			    "Unsupported LRW block size: %"PRIuGRUB_SIZE,
    ++			    "Unsupported LRW block size: %" PRIuGRUB_SIZE,
      			    cipher->cipher->blocksize);
      	  goto err;
      	}
    @@ grub-core/disk/cryptodisk.c: grub_cryptodisk_setcipher (grub_cryptodisk_t crypt,
      	  || cipher->cipher->blocksize == 0)
     -	grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported benbi blocksize: %d",
     +	grub_error (GRUB_ERR_BAD_ARGUMENT,
    -+		    "Unsupported benbi blocksize: %"PRIuGRUB_SIZE,
    ++		    "Unsupported benbi blocksize: %" PRIuGRUB_SIZE,
      		    cipher->cipher->blocksize);
      	/* FIXME should we return an error here? */
            for (benbi_log = 0;
    @@ grub-core/kern/efi/efi.c: grub_efi_duplicate_device_path (const grub_efi_device_
      	{
      	  grub_error (GRUB_ERR_OUT_OF_RANGE,
     -		      "malformed EFI Device Path node has length=%d", len);
    -+		      "malformed EFI Device Path node has length=%"PRIuGRUB_SIZE, len);
    ++		      "malformed EFI Device Path node has length=%" PRIuGRUB_SIZE, len);
      	  return NULL;
      	}
      
    @@ grub-core/loader/efi/chainloader.c: make_file_path (grub_efi_device_path_t *dp,
      	{
      	  grub_error (GRUB_ERR_OUT_OF_RANGE,
     -		      "malformed EFI Device Path node has length=%d", len);
    -+		      "malformed EFI Device Path node has length=%"PRIuGRUB_SIZE, len);
    ++		      "malformed EFI Device Path node has length=%" PRIuGRUB_SIZE, len);
      	  return NULL;
      	}
      
    @@ grub-core/loader/i386/bsd.c: grub_cmd_openbsd_ramdisk (grub_command_t cmd __attr
            grub_file_close (file);
            return grub_error (GRUB_ERR_BAD_OS, "your kOpenBSD supports ramdisk only"
     -			 " up to %u bytes, however you supplied a %u bytes one",
    -+			 " up to %"PRIuGRUB_SIZE" bytes, however you supplied"
    -+			 " a %"PRIuGRUB_SIZE" bytes one",
    ++			 " up to %" PRIuGRUB_SIZE " bytes, however you supplied"
    ++			 " a %" PRIuGRUB_SIZE " bytes one",
      			 openbsd_ramdisk.max_size, size);
          }

2: 30c3c79fe ! 2: bfff8c10f pgp: Format code for grub_error is incorrect

    @@ grub-core/commands/pgp.c: grub_verify_signature_real (struct grub_pubkey_context
          {
            /* TRANSLATORS: %08x is 32-bit key id.  */
     -      grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08x not found"),
    -+      grub_error (GRUB_ERR_BAD_SIGNATURE, N_("public key %08"PRIxGRUB_UINT64_T" not found"),
    - 		  keyid);
    +-		  keyid);
    ++      grub_error (GRUB_ERR_BAD_SIGNATURE,
    ++		  N_("public key %08" PRIxGRUB_UINT64_T " not found"), keyid);
            goto fail;
          }
    + 
 3:  ed754692d !  3:  df4e82eac efi: Format string error in grub_error
    @@ grub-core/kern/efi/mm.c: grub_efi_allocate_pages_real (grub_efi_physical_address
            grub_error (GRUB_ERR_BAD_ARGUMENT,
     -		  N_("invalid memory address (0x%llx > 0x%llx)"),
     -		  address, GRUB_EFI_MAX_USABLE_ADDRESS);
    -+		  N_("invalid memory address (0x%"PRIxGRUB_UINT64_T
    -+                     " > 0x%"PRIxGRUB_UINT64_T")"),
    ++		  N_("invalid memory address (0x%" PRIxGRUB_UINT64_T
    ++                     " > 0x%" PRIxGRUB_UINT64_T ")"),
     +		  address, (grub_efi_uint64_t) GRUB_EFI_MAX_USABLE_ADDRESS);
            return NULL;
          }
 4:  6a418777d =  4:  6846574fb error: Use PRI* macros to get correct format string code across architectures
 5:  ea743a1d4 <  -:  --------- error: Use format code PRIxGRUB_UINT64_T for 64-bit uint argument in grub_error
 -:  --------- >  5:  d059639a1 error: Use format code PRIxGRUB_UINT64_T for 64-bit uint argument in grub_error
 6:  40c210e62 !  6:  1bfdfa47e error: Use format code PRIxGRUB_UINT64_T for 64-bit arg in grub_error
    @@ grub-core/kern/ia64/dl.c: grub_arch_dl_relocate_symbols (grub_dl_t mod, void *eh
      	default:
      	  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
     -			     N_("relocation 0x%x is not implemented yet"),
    -+			     N_("relocation 0x%"PRIxGRUB_UINT64_T
    ++			     N_("relocation 0x%" PRIxGRUB_UINT64_T
     +				" is not implemented yet"),
      			     ELF_R_TYPE (rel->r_info));
      	}
    @@ grub-core/kern/riscv/dl.c: grub_arch_dl_relocate_symbols (grub_dl_t mod, void *e
      	  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
     -			     N_("relocation 0x%x is not implemented yet"),
     -			     ELF_R_TYPE (rel->r_info));
    -+			     N_("relocation 0x%"PRIxGRUB_UINT64_T
    ++			     N_("relocation 0x%" PRIxGRUB_UINT64_T
     +				" is not implemented yet"),
     +			     (grub_uint64_t) ELF_R_TYPE (rel->r_info));
      	}
    @@ grub-core/kern/sparc64/dl.c: grub_arch_dl_relocate_symbols (grub_dl_t mod, void
      	default:
      	  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
     -			     N_("relocation 0x%x is not implemented yet"),
    -+			     N_("relocation 0x%"PRIxGRUB_UINT64_T
    ++			     N_("relocation 0x%" PRIxGRUB_UINT64_T
     +				" is not implemented yet"),
      			     ELF_R_TYPE (rel->r_info));
      	}
    @@ grub-core/kern/x86_64/dl.c: grub_arch_dl_relocate_symbols (grub_dl_t mod, void *
      	default:
      	  return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
     -			     N_("relocation 0x%x is not implemented yet"),
    -+			     N_("relocation 0x%"PRIxGRUB_UINT64_T
    ++			     N_("relocation 0x%" PRIxGRUB_UINT64_T
     +			        " is not implemented yet"),
      			     ELF_R_TYPE (rel->r_info));
      	}
 7:  f9b7933f9 !  7:  bacdaf296 error: Use format code PRIuGRUB_UINT64_T for 64-bit typed fileblock in grub_error
    @@ grub-core/fs/hfsplus.c: grub_hfsplus_read_block (grub_fshelp_node_t node, grub_d
      	  grub_error (GRUB_ERR_READ_ERROR,
     -		      "no block found for the file id 0x%x and the block offset 0x%x",
     +		      "no block found for the file id 0x%x and the block"
    -+		      " offset 0x%"PRIuGRUB_UINT64_T,
    ++		      " offset 0x%" PRIuGRUB_UINT64_T,
      		      node->fileid, fileblock);
      	  break;
      	}

8: de6688623 ! 8: 88a885a40 error: Use format code llu for 64-bit uint bp->blk_prop in grub_error
@@ Metadata
## Commit message ##
error: Use format code llu for 64-bit uint bp->blk_prop in grub_error

- For some reason PRIuGRUB_UINT64_T is not expanding to llu, but to lu, which
- causes the format string check to fail. Use literal and force cast until
- this is debugged.
+ This is a temporary, less-intrusive change to get the build to success with
+ compiler format string checking turned on. There is a better fix which
+ addresses this issue, but it needs more testing. Use this change so that
+ format string checking on grub_error can be turned on until the better
+ change is fully tested.

## grub-core/fs/zfs/zfs.c ##
@@ grub-core/fs/zfs/zfs.c: zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf,
@@ grub-core/fs/zfs/zfs.c: zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void *
- "unsupported embedded BP (type=%u)\n",
- BPE_GET_ETYPE(bp));
+ "unsupported embedded BP (type=%llu)\n",
-+ (long long unsigned int)BPE_GET_ETYPE(bp));
++ (long long unsigned int) BPE_GET_ETYPE(bp));
lsize = BPE_GET_LSIZE(bp);
psize = BF64_GET_SB(grub_zfs_to_cpu64 ((bp)->blk_prop, endian), 25, 7, 0, 1);
}

 9:  d071036a3 =  9:  d4095f724 error: Do compile-time format string checking on grub_error
10:  bba547214 ! 10:  004d029b5 fixup: error: Use format code llu for 64-bit uint bp->blk_prop in grub_error

@@ Metadata
Author: Glenn Washburn <[email protected]>

## Commit message ##
- fixup: error: Use format code llu for 64-bit uint bp->blk_prop in grub_error
+ zfs: Use grub_uint64_t instead of 1ULL in BF64_*CODE macros
+
+ The underlying type of grub_uint64_t changes across architectures, but 1ULL
+ does not. This allows using these macros as arguments to format string
+ functions that use the PRI* format string macros that also vary with
+ architecture.
+
+ Change the grub_error call, where this was previously an issue and
+ temporarily fixed by casting and using a format string literal code, to now
+ use PRI* macros and remove casting.

## grub-core/fs/zfs/zfs.c ##
@@ grub-core/fs/zfs/zfs.c: zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf,
@@ grub-core/fs/zfs/zfs.c: zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void *
if (BPE_GET_ETYPE(bp) != BP_EMBEDDED_TYPE_DATA)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- "unsupported embedded BP (type=%llu)\n",
-- (long long unsigned int)BPE_GET_ETYPE(bp));
+- (long long unsigned int) BPE_GET_ETYPE(bp));
+ "unsupported embedded BP (type=%"
+ PRIuGRUB_UINT64_T ")\n",
+ BPE_GET_ETYPE(bp));

Signature · 1 line
2.27.0