From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lHyFS-0004IN-7R for mharc-grub-devel@gnu.org; Thu, 04 Mar 2021 19:23:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHyFO-0004HK-Em for grub-devel@gnu.org; Thu, 04 Mar 2021 19:23:16 -0500 Received: from mail-qv1-xf33.google.com ([2607:f8b0:4864:20::f33]:47004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lHyFI-0006MA-Jk for grub-devel@gnu.org; Thu, 04 Mar 2021 19:23:12 -0500 Received: by mail-qv1-xf33.google.com with SMTP id 15so163282qvp.13 for ; Thu, 04 Mar 2021 16:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mm69QDAVt1jOjI9AQ2uMFoBCRoCQcRNQE++nSCFTeHc=; b=KqnfhEWln84KqrvoVtmknFPdc3qCJZKeb/Q3He/jVwLdMi6C9P22WnR6f+J8RR0L+F BruE85GZBracmITOkaIfZNucmOTUZoZ0dUb6IIiYdsj9XSHycAwv4M53K3uvvRvoDtXg /1gU1Uj5yEdgPAWqtmToQCEjFTcW1iXNasc+zc4q3jg4IcLDuM7/iE+A8ralJT1wZpo8 QVFxNsdC4CFU0YRkyKDbXzCRCfTSJlyDQ6zD63Z4tke1tXhl/4G3pCHibkTj2jRgQX/i RsC8KE9Bx1+6dAO4t5QIxtxzDKnkYaZTBBD/Yz8p0/jlDkspvcmC1BlhwTxOvjCY+zWk OdiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mm69QDAVt1jOjI9AQ2uMFoBCRoCQcRNQE++nSCFTeHc=; b=WxA8EgRr+Ql1Vab1FCL/2AnSmQUKnlsrlOhy46JK6cN2oUbd3ykxOF1yPArlNuEEZZ /GA216NwTWDUKTj8r+fzkXGmEPftHkaS89S3PFZWyn1GG9yap7k1ybo9uyNtTksnu9GW suTxTDvdNYkwUirrihtiaehqxwUZ/jQBN3/mcOxKYon6GHtnGWCd+0HU4UIXNnOEovNU P0iqD9B8ZtCHlSOmLsnglbNPPOV6vdgoJcAC7vxJP+Ehg9gqYNT6gNEmakE/upcxcf8g SlKwcWscxIUt2JhpU7cnZaWOW+JDZlombnLUUvfq27yJrR0Tfcrp9IPnJmXfiUsCSYjD 2JrQ== X-Gm-Message-State: AOAM530imixiimRjydXUBrCBGsCZiLClxxwdO85QDqQpWla82nNnP99O dB+eqh4CStTUr+Lfe/scpjWzdG3J3neFHg== X-Google-Smtp-Source: ABdhPJxbstLLfEBWwslZsw0I+8QjRrphDrhZe6PITffHRd9vxx6kVDCj+67AuZGpWnLok8YrskmXGA== X-Received: by 2002:ad4:4692:: with SMTP id bq18mr6874279qvb.0.1614903785750; Thu, 04 Mar 2021 16:23:05 -0800 (PST) Received: from localhost.localdomain ([2605:a601:aac5:3700:9763:81c2:19e4:8a8f]) by smtp.gmail.com with ESMTPSA id 75sm674558qkd.114.2021.03.04.16.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 16:23:05 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH v6 00/14] error: Do compile-time format string checking on grub> Date: Thu, 4 Mar 2021 18:22:31 -0600 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::f33; envelope-from=development@efficientek.com; helo=mail-qv1-xf33.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Mar 2021 00:23:16 -0000 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 ## 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)); -- 2.27.0