From: Glenn Washburn <development@efficientek.com>
To: grub-devel@gnu.org
Cc: Glenn Washburn <development@efficientek.com>
Subject: [PATCH] error: Do compile-time format string checking on grub_error.
Date: Fri, 31 Jul 2020 09:33:18 -0500 [thread overview]
Message-ID: <20200731143323.1650165-1-development@efficientek.com> (raw)
Fix the many issues this uncovered mostly related to incorrect length
modifiers.
Signed-off-by: Glenn Washburn <development@efficientek.com>
---
grub-core/commands/pgp.c | 2 +-
grub-core/disk/ata.c | 4 ++--
grub-core/disk/cryptodisk.c | 8 ++++----
grub-core/disk/dmraid_nvidia.c | 2 +-
grub-core/fs/hfsplus.c | 2 +-
grub-core/fs/zfs/zfs.c | 2 +-
grub-core/kern/efi/efi.c | 2 +-
grub-core/kern/efi/mm.c | 2 +-
grub-core/kern/x86_64/dl.c | 2 +-
grub-core/loader/efi/chainloader.c | 4 ++--
grub-core/loader/i386/bsd.c | 2 +-
grub-core/loader/i386/pc/linux.c | 4 ++--
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 ++-
17 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/grub-core/commands/pgp.c b/grub-core/commands/pgp.c
index bbf6871fe..7c2fef6d0 100644
--- a/grub-core/commands/pgp.c
+++ b/grub-core/commands/pgp.c
@@ -633,7 +633,7 @@ grub_verify_signature_real (struct grub_pubkey_context *ctxt,
if (!sk)
{
/* 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 %08lx not found"),
keyid);
goto fail;
}
diff --git a/grub-core/disk/ata.c b/grub-core/disk/ata.c
index 685f33a19..f401a27cf 100644
--- a/grub-core/disk/ata.c
+++ b/grub-core/disk/ata.c
@@ -219,7 +219,7 @@ grub_ata_setaddress (struct grub_ata *dev,
if (dev->sectors_per_track == 0
|| dev->heads == 0)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
- "sector %d cannot be addressed "
+ "sector %ld cannot be addressed "
"using CHS addressing", sector);
/* Calculate the sector, cylinder and head to use. */
@@ -232,7 +232,7 @@ grub_ata_setaddress (struct grub_ata *dev,
|| cylinder > dev->cylinders
|| head > dev->heads)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
- "sector %d cannot be addressed "
+ "sector %ld cannot be addressed "
"using CHS addressing", sector);
parms->taskfile.disk = 0xE0 | head;
diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index 4921d031d..9d2f0d635 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -476,13 +476,13 @@ grub_cryptodisk_setcipher (grub_cryptodisk_t crypt, const char *ciphername, cons
}
if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES)
{
- ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d",
+ ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %ld",
cipher->cipher->blocksize);
goto err;
}
if (secondary_cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES)
{
- ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %d",
+ ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported XTS block size: %ld",
secondary_cipher->cipher->blocksize);
goto err;
}
@@ -493,7 +493,7 @@ grub_cryptodisk_setcipher (grub_cryptodisk_t crypt, const char *ciphername, cons
cipheriv = ciphermode + sizeof ("lrw-") - 1;
if (cipher->cipher->blocksize != GRUB_CRYPTODISK_GF_BYTES)
{
- ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %d",
+ ret = grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported LRW block size: %ld",
cipher->cipher->blocksize);
goto err;
}
@@ -515,7 +515,7 @@ grub_cryptodisk_setcipher (grub_cryptodisk_t crypt, const char *ciphername, cons
{
if (cipher->cipher->blocksize & (cipher->cipher->blocksize - 1)
|| cipher->cipher->blocksize == 0)
- grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported benbi blocksize: %d",
+ grub_error (GRUB_ERR_BAD_ARGUMENT, "Unsupported benbi blocksize: %ld",
cipher->cipher->blocksize);
/* FIXME should we return an error here? */
for (benbi_log = 0;
diff --git a/grub-core/disk/dmraid_nvidia.c b/grub-core/disk/dmraid_nvidia.c
index 060279124..014581df0 100644
--- a/grub-core/disk/dmraid_nvidia.c
+++ b/grub-core/disk/dmraid_nvidia.c
@@ -122,7 +122,7 @@ grub_dmraid_nv_detect (grub_disk_t disk,
if (sb.version != NV_VERSION)
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- "unknown version: %d.%d", sb.version);
+ "unknown version: %d", sb.version);
return NULL;
}
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
index 9c4e4c88c..112334504 100644
--- a/grub-core/fs/hfsplus.c
+++ b/grub-core/fs/hfsplus.c
@@ -188,7 +188,7 @@ grub_hfsplus_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
|| !nnode)
{
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%lx",
node->fileid, fileblock);
break;
}
diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c
index 41ef0ff57..9ad26e876 100644
--- a/grub-core/fs/zfs/zfs.c
+++ b/grub-core/fs/zfs/zfs.c
@@ -1869,7 +1869,7 @@ zio_read (blkptr_t *bp, grub_zfs_endian_t endian, void **buf,
{
if (BPE_GET_ETYPE(bp) != BP_EMBEDDED_TYPE_DATA)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- "unsupported embedded BP (type=%u)\n",
+ "unsupported embedded BP (type=%llu)\n",
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);
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
index e0165e74c..a56be538c 100644
--- a/grub-core/kern/efi/efi.c
+++ b/grub-core/kern/efi/efi.c
@@ -491,7 +491,7 @@ grub_efi_duplicate_device_path (const grub_efi_device_path_t *dp)
if (len < 4)
{
grub_error (GRUB_ERR_OUT_OF_RANGE,
- "malformed EFI Device Path node has length=%d", len);
+ "malformed EFI Device Path node has length=%ld", len);
return NULL;
}
diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c
index 457772d57..22f89b6af 100644
--- a/grub-core/kern/efi/mm.c
+++ b/grub-core/kern/efi/mm.c
@@ -127,7 +127,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
if (address > GRUB_EFI_MAX_USABLE_ADDRESS)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("invalid memory address (0x%llx > 0x%llx)"),
+ N_("invalid memory address (0x%lx > 0x%x)"),
address, GRUB_EFI_MAX_USABLE_ADDRESS);
return NULL;
}
diff --git a/grub-core/kern/x86_64/dl.c b/grub-core/kern/x86_64/dl.c
index 3a73e6e6c..aa01cc167 100644
--- a/grub-core/kern/x86_64/dl.c
+++ b/grub-core/kern/x86_64/dl.c
@@ -107,7 +107,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr,
default:
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
- N_("relocation 0x%x is not implemented yet"),
+ N_("relocation 0x%lx is not implemented yet"),
ELF_R_TYPE (rel->r_info));
}
}
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
index 7b31c3fb9..eab78269c 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -90,7 +90,7 @@ grub_chainloader_boot (void)
*grub_utf16_to_utf8 ((grub_uint8_t *) buf,
exit_data, exit_data_size) = 0;
- grub_error (GRUB_ERR_BAD_OS, buf);
+ grub_error (GRUB_ERR_BAD_OS, "%s", buf);
grub_free (buf);
}
}
@@ -164,7 +164,7 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename)
if (len < 4)
{
grub_error (GRUB_ERR_OUT_OF_RANGE,
- "malformed EFI Device Path node has length=%d", len);
+ "malformed EFI Device Path node has length=%ld", len);
return NULL;
}
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
index f5bf7f89e..9d00884ae 100644
--- a/grub-core/loader/i386/bsd.c
+++ b/grub-core/loader/i386/bsd.c
@@ -2110,7 +2110,7 @@ grub_cmd_openbsd_ramdisk (grub_command_t cmd __attribute__ ((unused)),
{
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 %lu bytes, however you supplied a %lu bytes one",
openbsd_ramdisk.max_size, size);
}
diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
index 814988ab9..0bc5d6807 100644
--- a/grub-core/loader/i386/pc/linux.c
+++ b/grub-core/loader/i386/pc/linux.c
@@ -230,9 +230,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
&& GRUB_LINUX_ZIMAGE_ADDR + grub_linux16_prot_size
> grub_linux_real_target)
{
- grub_error (GRUB_ERR_BAD_OS, "too big zImage (0x%x > 0x%x), use bzImage instead",
+ grub_error (GRUB_ERR_BAD_OS, "too big zImage (%p > %p), use bzImage instead",
(char *) GRUB_LINUX_ZIMAGE_ADDR + grub_linux16_prot_size,
- (grub_size_t) grub_linux_real_target);
+ (void *) grub_linux_real_target);
goto fail;
}
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
index 644135caf..dd2462bb0 100644
--- a/grub-core/net/tftp.c
+++ b/grub-core/net/tftp.c
@@ -241,7 +241,7 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
case TFTP_ERROR:
data->have_oack = 1;
grub_netbuff_free (nb);
- grub_error (GRUB_ERR_IO, (char *) tftph->u.err.errmsg);
+ grub_error (GRUB_ERR_IO, "%s", tftph->u.err.errmsg);
grub_error_save (&data->save_err);
return GRUB_ERR_NONE;
default:
diff --git a/grub-core/parttool/msdospart.c b/grub-core/parttool/msdospart.c
index dcbf74e3b..2e2e9d527 100644
--- a/grub-core/parttool/msdospart.c
+++ b/grub-core/parttool/msdospart.c
@@ -127,8 +127,8 @@ static grub_err_t grub_pcpart_type (const grub_device_t dev,
{
dev->disk->partition = part;
return grub_error (GRUB_ERR_BAD_ARGUMENT,
- N_("the partition type 0x%x isn't "
- "valid"));
+ N_("the partition type 0x%x isn't valid"),
+ type);
}
mbr.entries[index].type = type;
diff --git a/grub-core/script/lexer.c b/grub-core/script/lexer.c
index 5fb0cbd0b..27daad791 100644
--- a/grub-core/script/lexer.c
+++ b/grub-core/script/lexer.c
@@ -349,7 +349,7 @@ void
grub_script_yyerror (struct grub_parser_param *state, char const *err)
{
if (err)
- grub_error (GRUB_ERR_INVALID_COMMAND, err);
+ grub_error (GRUB_ERR_INVALID_COMMAND, "%s", err);
grub_print_error ();
state->err++;
diff --git a/grub-core/video/bochs.c b/grub-core/video/bochs.c
index 3bcfa53a9..6d640c0e2 100644
--- a/grub-core/video/bochs.c
+++ b/grub-core/video/bochs.c
@@ -249,11 +249,11 @@ grub_video_bochs_setup (unsigned int width, unsigned int height,
}
if (width > BOCHS_MAX_WIDTH)
- return grub_error (GRUB_ERR_IO, "width must be at most",
+ return grub_error (GRUB_ERR_IO, "width must be at most %d",
BOCHS_MAX_WIDTH);
if (height > BOCHS_MAX_HEIGHT)
- return grub_error (GRUB_ERR_IO, "height must be at most",
+ return grub_error (GRUB_ERR_IO, "height must be at most %d",
BOCHS_MAX_HEIGHT);
if (width & (BOCHS_WIDTH_ALIGN - 1))
diff --git a/include/grub/err.h b/include/grub/err.h
index 24ba9f5f5..b08d5d0de 100644
--- a/include/grub/err.h
+++ b/include/grub/err.h
@@ -85,7 +85,8 @@ struct grub_error_saved
extern grub_err_t EXPORT_VAR(grub_errno);
extern char EXPORT_VAR(grub_errmsg)[GRUB_MAX_ERRMSG];
-grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...);
+grub_err_t EXPORT_FUNC(grub_error) (grub_err_t n, const char *fmt, ...)
+ __attribute__ ((format (GNU_PRINTF, 2, 3)));
void EXPORT_FUNC(grub_fatal) (const char *fmt, ...) __attribute__ ((noreturn));
void EXPORT_FUNC(grub_error_push) (void);
int EXPORT_FUNC(grub_error_pop) (void);
--
2.25.1
next reply other threads:[~2020-07-31 14:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-31 14:33 Glenn Washburn [this message]
2020-07-31 14:33 ` [PATCH] cryptodisk: Use cipher name instead of object in error message Glenn Washburn
2020-09-17 14:30 ` Daniel Kiper
2020-07-31 14:33 ` [PATCH] lexer: char const * should be const char * Glenn Washburn
2020-09-17 14:33 ` Daniel Kiper
2020-07-31 14:33 ` [PATCH] docs/grub: Support for loading and concatenating multiple initrds Glenn Washburn
2020-09-17 14:36 ` Daniel Kiper
2020-07-31 14:33 ` [PATCH] script: Do not allow a delimiter between function name and block start Glenn Washburn
2020-09-17 14:40 ` Daniel Kiper
2020-07-31 14:33 ` [PATCH] crypto: Remove GPG_ERROR_CFLAGS from gpg_err_code_t enum Glenn Washburn
2020-09-17 14:42 ` Daniel Kiper
2020-09-17 14:29 ` [PATCH] error: Do compile-time format string checking on grub_error Daniel Kiper
2020-10-03 22:34 ` Glenn Washburn
2020-10-05 6:12 ` Glenn Washburn
2020-10-05 6:17 ` Glenn Washburn
2020-11-08 5:26 ` [PATCH v2 0/2] " Glenn Washburn
2020-11-08 5:26 ` [PATCH v2 1/2] error: Fix issues mostly related to incorrect length modifiers in calls to grub_error() Glenn Washburn
2020-11-08 5:26 ` [PATCH v2 2/2] error: Do compile-time format string checking on grub_error Glenn Washburn
2020-11-23 9:31 ` [PATCH v2 0/2] " Glenn Washburn
2020-12-01 5:59 ` Glenn Washburn
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=20200731143323.1650165-1-development@efficientek.com \
--to=development@efficientek.com \
--cc=grub-devel@gnu.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.