Changeset View
Changeset View
Standalone View
Standalone View
files/fix-sprintf-formatting.patch
- This file was added.
| From cd8f7d79f84155d1dfbff3bb169558a8b06fb719 Mon Sep 17 00:00:00 2001 | |||||
| From: Peter Jones <pjones@redhat.com> | |||||
| Date: Fri, 19 May 2017 16:39:56 -0400 | |||||
| Subject: [PATCH] Fix sprintf formatting for Boot####. | |||||
| MIME-Version: 1.0 | |||||
| Content-Type: text/plain; charset=UTF-8 | |||||
| Content-Transfer-Encoding: 8bit | |||||
| If you give it enough compiler flags, gcc believes the following: | |||||
| ----------------------- | |||||
| libfwup.c: In function ‘set_up_boot_next’: | |||||
| libfwup.c:1049:27: error: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Werror=format-overflow=] | |||||
| sprintf(boot_next_name, "Boot%04X", boot_next); | |||||
| ^~~~~~~~~~ | |||||
| In file included from /usr/include/stdio.h:939:0, | |||||
| from libfwup.c:17: | |||||
| /usr/include/bits/stdio2.h:33:10: note: ‘__builtin___sprintf_chk’ output between 9 and 10 bytes into a destination of size 9 | |||||
| return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1, | |||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |||||
| __bos (__s), __fmt, __va_arg_pack ()); | |||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |||||
| cc1: all warnings being treated as errors | |||||
| make[1]: *** [Makefile:70: libfwup.o] Error 1 | |||||
| make[1]: Leaving directory '/home/pjones/devel/rhel/fwupdate/fwupdate-9/linux' | |||||
| make: *** [Makefile:10: all] Error 2 | |||||
| ----------------------- | |||||
| The code in question is: | |||||
| ----------------------- | |||||
| if (boot_next >= 0x10000) { | |||||
| efi_error("no free boot variables!"); | |||||
| goto out; | |||||
| } | |||||
| sprintf(boot_next_name, "Boot%04X", boot_next); | |||||
| ----------------------- | |||||
| It really should know it can't be a higher value than 0xffff. Even | |||||
| so, while it's not true that this can happen, since we never get to that | |||||
| code if boot_next is > 0xffff, the compiler can't figure that out, so | |||||
| it's complaining about an int being crammed into 4 bytes of hex. | |||||
| So this patch just tells it the maximum value is 0xffff. | |||||
| Signed-off-by: Peter Jones <pjones@redhat.com> | |||||
| --- | |||||
| linux/libfwup.c | 2 +- | |||||
| 1 file changed, 1 insertion(+), 1 deletion(-) | |||||
| diff --git a/linux/libfwup.c b/linux/libfwup.c | |||||
| index 929c106..1b9b72a 100644 | |||||
| --- a/linux/libfwup.c | |||||
| +++ b/linux/libfwup.c | |||||
| @@ -1046,7 +1046,7 @@ set_up_boot_next(void) | |||||
| goto out; | |||||
| } | |||||
| - sprintf(boot_next_name, "Boot%04X", boot_next); | |||||
| + sprintf(boot_next_name, "Boot%04hX", boot_next & 0xffff); | |||||
| rc = efi_set_variable(efi_guid_global, boot_next_name, opt, | |||||
| opt_size, | |||||
| EFI_VARIABLE_NON_VOLATILE | | |||||
Copyright © 2015-2021 Solus Project. The Solus logo is Copyright © 2016-2021 Solus Project. All Rights Reserved.