From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH 1/7] mkeficapsule: Correct printf() strings
Date: Mon, 8 Feb 2021 00:20:57 +0100 [thread overview]
Message-ID: <5ebe9bae-eefc-d1a6-fa09-a692c494edfe@gmx.de> (raw)
In-Reply-To: <20210207212707.3958570-2-sjg@chromium.org>
On 2/7/21 10:27 PM, Simon Glass wrote:
> Use %z when printing size_t values. This avoids errors on 32-bit
> machines.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> tools/mkeficapsule.c | 14 +++++++-------
> 1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c
> index 162494907a8..ea6151989e9 100644
> --- a/tools/mkeficapsule.c
> +++ b/tools/mkeficapsule.c
> @@ -278,7 +278,7 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
> }
> data = malloc(bin_stat.st_size);
> if (!data) {
> - printf("cannot allocate memory: %lx\n", bin_stat.st_size);
> + printf("cannot allocate memory: %lx\n", (ulong)bin_stat.st_size);
Thanks for addressing the build problem.
bin_stat.st_size is of type off_t which may be u64 on 32bit systems.
We must check that bin_stat.st_size <= SIZE_MAX before calling malloc()
otherwise the value may be truncated.
The capsule file will end up on a FAT file system which has a file size
limit of 2^32-1. Typically the ESP has a size of 100 MiB. We should at
least check that bin_stat.st_size <= 2^32-1.
Converting to size_t instead of ulong seems to be the natural choice for
a parameter called size.
> goto err_1;
> }
> f = fopen(path, "w");
> @@ -297,7 +297,7 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
>
> size = fwrite(&header, 1, sizeof(header), f);
> if (size < sizeof(header)) {
> - printf("write failed (%lx)\n", size);
> + printf("write failed (%zx)\n", size);
ok
> goto err_3;
> }
>
> @@ -306,13 +306,13 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
> capsule.payload_item_count = 1;
> size = fwrite(&capsule, 1, sizeof(capsule), f);
> if (size < (sizeof(capsule))) {
> - printf("write failed (%lx)\n", size);
> + printf("write failed (%zx)\n", size);
ok
> goto err_3;
> }
> offset = sizeof(capsule) + sizeof(u64);
> size = fwrite(&offset, 1, sizeof(offset), f);
> if (size < sizeof(offset)) {
> - printf("write failed (%lx)\n", size);
> + printf("write failed (%zx)\n", size);
ok
> goto err_3;
> }
>
> @@ -329,17 +329,17 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid,
>
> size = fwrite(&image, 1, sizeof(image), f);
> if (size < sizeof(image)) {
> - printf("write failed (%lx)\n", size);
> + printf("write failed (%zx)\n", size);
ok
> goto err_3;
> }
> size = fread(data, 1, bin_stat.st_size, g);
> if (size < bin_stat.st_size) {
> - printf("read failed (%lx)\n", size);
> + printf("read failed (%zx)\n", size);
ok
> goto err_3;
> }
> size = fwrite(data, 1, bin_stat.st_size, f);
> if (size < bin_stat.st_size) {
> - printf("write failed (%lx)\n", size);
> + printf("write failed (%zx)\n", size);
ok
Best regards
Heinrich
> goto err_3;
> }
>
>
next prev parent reply other threads:[~2021-02-07 23:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-07 21:27 [PATCH 0/7] Fix compiler warnings for 32-bit ARM Simon Glass
2021-02-07 21:27 ` [PATCH 1/7] mkeficapsule: Correct printf() strings Simon Glass
2021-02-07 23:20 ` Heinrich Schuchardt [this message]
2021-02-07 21:27 ` [PATCH 2/7] efi: Fix compiler warnings Simon Glass
2021-02-07 21:49 ` Heinrich Schuchardt
2021-02-07 21:27 ` [PATCH 3/7] pci: swap_case: Allow compilation on 32-bit machines Simon Glass
2021-02-07 21:34 ` Heinrich Schuchardt
2021-02-07 21:27 ` [PATCH 4/7] tpm: Correct warning on 32-bit build Simon Glass
2021-02-07 21:31 ` Heinrich Schuchardt
2021-03-15 15:52 ` Tom Rini
2021-02-07 21:27 ` [PATCH 5/7] test: acpi: Fix warnings " Simon Glass
2021-03-15 15:52 ` Tom Rini
2021-02-07 21:27 ` [PATCH 6/7] doc: sandbox: Fix up dependencies Simon Glass
2021-02-07 21:30 ` Heinrich Schuchardt
2021-02-07 21:27 ` [PATCH 7/7] doc: sandbox: Update instructions on quitting Simon Glass
2021-03-15 15:52 ` Tom Rini
2021-03-15 17:06 ` [PATCH 0/7] Fix compiler warnings for 32-bit ARM Heinrich Schuchardt
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=5ebe9bae-eefc-d1a6-fa09-a692c494edfe@gmx.de \
--to=xypron.glpk@gmx.de \
--cc=u-boot@lists.denx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox