All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/x86_64: Fix format warning with die()
@ 2017-03-14 12:29 Pratyush Anand
  2017-03-14 13:39 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: Pratyush Anand @ 2017-03-14 12:29 UTC (permalink / raw)
  To: horms; +Cc: Pratyush Anand, dyoung, kexec, bhe

Fedora koji uses gcc version 7.0.1-0.12.fc27, and it generates a build
warning

   kexec/arch/i386/kexec-elf-x86.c:299:3: error: format not a string
   literal and no format arguments [-Werror=format-security]
       die(error_msg);
       ^~~
    cc1: some warnings being treated as errors

error_msg can have a format specifier as well in string. In such cases,
if there is no other arguments for the format variable then code will
try to access a non existing argument. Therefore, use 1st argument as
format specifier for string print and pass error_msg as the string to be
printed.

While doing that,also use const qualifier before "char *error_msg".

Signed-off-by: Pratyush Anand <panand@redhat.com>
---
 kexec/arch/i386/kexec-elf-x86.c      | 4 ++--
 kexec/arch/x86_64/kexec-elf-x86_64.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/kexec/arch/i386/kexec-elf-x86.c b/kexec/arch/i386/kexec-elf-x86.c
index de00dcb869d7..fedf031cdf4a 100644
--- a/kexec/arch/i386/kexec-elf-x86.c
+++ b/kexec/arch/i386/kexec-elf-x86.c
@@ -91,7 +91,7 @@ int elf_x86_load(int argc, char **argv, const char *buf, off_t len,
 	char *command_line = NULL, *modified_cmdline = NULL;
 	const char *append = NULL;
 	char *tmp_cmdline = NULL;
-	char *error_msg = NULL;
+	const char *error_msg = NULL;
 	int result;
 	int command_line_len;
 	const char *ramdisk;
@@ -296,6 +296,6 @@ out:
 	free(command_line);
 	free(modified_cmdline);
 	if (error_msg)
-		die(error_msg);
+		die("%s", error_msg);
 	return result;
 }
diff --git a/kexec/arch/x86_64/kexec-elf-x86_64.c b/kexec/arch/x86_64/kexec-elf-x86_64.c
index ae6569220bc8..ad2231193eb1 100644
--- a/kexec/arch/x86_64/kexec-elf-x86_64.c
+++ b/kexec/arch/x86_64/kexec-elf-x86_64.c
@@ -99,7 +99,7 @@ int elf_x86_64_load(int argc, char **argv, const char *buf, off_t len,
 #define ARG_STYLE_NONE  2
 	int opt;
 	int result = 0;
-	char *error_msg = NULL;
+	const char *error_msg = NULL;
 
 	/* See options.h and add any new options there too! */
 	static const struct option options[] = {
@@ -276,6 +276,6 @@ out:
 	free(command_line);
 	free(modified_cmdline);
 	if (error_msg)
-		die(error_msg);
+		die("%s", error_msg);
 	return result;
 }
-- 
2.9.3


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/x86_64: Fix format warning with die()
  2017-03-14 12:29 [PATCH] x86/x86_64: Fix format warning with die() Pratyush Anand
@ 2017-03-14 13:39 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2017-03-14 13:39 UTC (permalink / raw)
  To: Pratyush Anand; +Cc: dyoung, kexec, bhe

On Tue, Mar 14, 2017 at 05:59:22PM +0530, Pratyush Anand wrote:
> Fedora koji uses gcc version 7.0.1-0.12.fc27, and it generates a build
> warning
> 
>    kexec/arch/i386/kexec-elf-x86.c:299:3: error: format not a string
>    literal and no format arguments [-Werror=format-security]
>        die(error_msg);
>        ^~~
>     cc1: some warnings being treated as errors
> 
> error_msg can have a format specifier as well in string. In such cases,
> if there is no other arguments for the format variable then code will
> try to access a non existing argument. Therefore, use 1st argument as
> format specifier for string print and pass error_msg as the string to be
> printed.
> 
> While doing that,also use const qualifier before "char *error_msg".
> 
> Signed-off-by: Pratyush Anand <panand@redhat.com>

Thanks, applied.

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-14 13:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 12:29 [PATCH] x86/x86_64: Fix format warning with die() Pratyush Anand
2017-03-14 13:39 ` Simon Horman

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.