All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] modpost: fix asprintf warnings
@ 2009-12-09 12:02 Mike Frysinger
  2009-12-09 15:59 ` Américo Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Mike Frysinger @ 2009-12-09 12:02 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel

On compilers with security warnings enabled by default, we get:

scripts/mod/modpost.c: In function 'get_markers':
scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
                                     declared with attribute warn_unused_result
scripts/mod/modpost.c: In function 'add_marker':
scripts/mod/modpost.c:1982: warning: ignoring return value of 'asprintf',
                                     declared with attribute warn_unused_result

So check the return value and abort on errors.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 scripts/mod/modpost.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 801a16a..c4df538 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1559,7 +1559,8 @@ static void get_markers(struct elf_info *info, struct module *mod)
 			const char *name = strings + sym->st_value;
 			const char *fmt = strchr(name, '\0') + 1;
 			char *line = NULL;
-			asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
+			if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
+				fatal("asprintf() with %s failed", name);
 			NOFAIL(line);
 			mod->markers[n++] = line;
 		}
@@ -1979,7 +1980,8 @@ static void write_dump(const char *fname)
 static void add_marker(struct module *mod, const char *name, const char *fmt)
 {
 	char *line = NULL;
-	asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
+	if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
+		fatal("asprintf() with %s failed", name);
 	NOFAIL(line);
 
 	mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) *
-- 
1.6.5.5


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

* Re: [PATCH] modpost: fix asprintf warnings
  2009-12-09 12:02 [PATCH] modpost: fix asprintf warnings Mike Frysinger
@ 2009-12-09 15:59 ` Américo Wang
  2009-12-09 20:31   ` Mike Frysinger
  2009-12-10  1:16   ` [PATCH v2] " Mike Frysinger
  0 siblings, 2 replies; 8+ messages in thread
From: Américo Wang @ 2009-12-09 15:59 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: Rusty Russell, linux-kernel

On Wed, Dec 09, 2009 at 07:02:23AM -0500, Mike Frysinger wrote:
>On compilers with security warnings enabled by default, we get:
>
>scripts/mod/modpost.c: In function 'get_markers':
>scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
>                                     declared with attribute warn_unused_result
>scripts/mod/modpost.c: In function 'add_marker':
>scripts/mod/modpost.c:1982: warning: ignoring return value of 'asprintf',
>                                     declared with attribute warn_unused_result
>
>So check the return value and abort on errors.
>
>Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>---
> scripts/mod/modpost.c |    6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
>index 801a16a..c4df538 100644
>--- a/scripts/mod/modpost.c
>+++ b/scripts/mod/modpost.c
>@@ -1559,7 +1559,8 @@ static void get_markers(struct elf_info *info, struct module *mod)
> 			const char *name = strings + sym->st_value;
> 			const char *fmt = strchr(name, '\0') + 1;
> 			char *line = NULL;
>-			asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
>+			if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
>+				fatal("asprintf() with %s failed", name);

A '\n' is needed.

> 			NOFAIL(line);
> 			mod->markers[n++] = line;
> 		}
>@@ -1979,7 +1980,8 @@ static void write_dump(const char *fname)
> static void add_marker(struct module *mod, const char *name, const char *fmt)
> {
> 	char *line = NULL;
>-	asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
>+	if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
>+		fatal("asprintf() with %s failed", name);
> 	NOFAIL(line);
> 
> 	mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) *
>-- 
>1.6.5.5
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

-- 
Live like a child, think like the god.
 

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

* Re: [PATCH] modpost: fix asprintf warnings
  2009-12-09 15:59 ` Américo Wang
@ 2009-12-09 20:31   ` Mike Frysinger
  2009-12-10  1:16   ` [PATCH v2] " Mike Frysinger
  1 sibling, 0 replies; 8+ messages in thread
From: Mike Frysinger @ 2009-12-09 20:31 UTC (permalink / raw)
  To: Américo Wang; +Cc: Rusty Russell, linux-kernel

On Wed, Dec 9, 2009 at 10:59, Américo Wang wrote:
> On Wed, Dec 09, 2009 at 07:02:23AM -0500, Mike Frysinger wrote:
>>--- a/scripts/mod/modpost.c
>>+++ b/scripts/mod/modpost.c
>>@@ -1559,7 +1559,8 @@ static void get_markers(struct elf_info *info, struct module *mod)
>>                       const char *name = strings + sym->st_value;
>>                       const char *fmt = strchr(name, '\0') + 1;
>>                       char *line = NULL;
>>-                      asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
>>+                      if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
>>+                              fatal("asprintf() with %s failed", name);
>
> A '\n' is needed.

hmm, i thought fatal() appended a new line automatically.  must have
been thinking of one of the other utils.
-mike

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

* [PATCH v2] modpost: fix asprintf warnings
  2009-12-09 15:59 ` Américo Wang
  2009-12-09 20:31   ` Mike Frysinger
@ 2009-12-10  1:16   ` Mike Frysinger
  2009-12-10  6:52     ` Américo Wang
  2009-12-10 11:07     ` Rusty Russell
  1 sibling, 2 replies; 8+ messages in thread
From: Mike Frysinger @ 2009-12-10  1:16 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1738 bytes --]

On compilers with security warnings enabled by default, we get:

scripts/mod/modpost.c: In function 'get_markers':
scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
                                     declared with attribute warn_unused_result
scripts/mod/modpost.c: In function 'add_marker':
scripts/mod/modpost.c:1982: warning: ignoring return value of 'asprintf',
                                     declared with attribute warn_unused_result

So check the return value and abort on errors.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
	- add missing newline pointed out by Américo Wang

 scripts/mod/modpost.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 801a16a..6608ebd 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1559,7 +1559,8 @@ static void get_markers(struct elf_info *info, struct module *mod)
 			const char *name = strings + sym->st_value;
 			const char *fmt = strchr(name, '\0') + 1;
 			char *line = NULL;
-			asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
+			if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
+				fatal("asprintf() with %s failed\n", name);
 			NOFAIL(line);
 			mod->markers[n++] = line;
 		}
@@ -1979,7 +1980,8 @@ static void write_dump(const char *fname)
 static void add_marker(struct module *mod, const char *name, const char *fmt)
 {
 	char *line = NULL;
-	asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
+	if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
+		fatal("asprintf() with %s failed\n", name);
 	NOFAIL(line);
 
 	mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) *
-- 
1.6.5.5


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

* Re: [PATCH v2] modpost: fix asprintf warnings
  2009-12-10  1:16   ` [PATCH v2] " Mike Frysinger
@ 2009-12-10  6:52     ` Américo Wang
  2009-12-10 11:07     ` Rusty Russell
  1 sibling, 0 replies; 8+ messages in thread
From: Américo Wang @ 2009-12-10  6:52 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: Rusty Russell, linux-kernel

On Thu, Dec 10, 2009 at 9:16 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On compilers with security warnings enabled by default, we get:
>
> scripts/mod/modpost.c: In function 'get_markers':
> scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
>                                     declared with attribute warn_unused_result
> scripts/mod/modpost.c: In function 'add_marker':
> scripts/mod/modpost.c:1982: warning: ignoring return value of 'asprintf',
>                                     declared with attribute warn_unused_result
>
> So check the return value and abort on errors.
>
> Signed-off-by: Mike Frysinger <vapier@gentoo.org>


Acked-by: WANG Cong <xiyou.wangcong@gmail.com>

> ---
> v2
>        - add missing newline pointed out by Américo Wang
>
>  scripts/mod/modpost.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 801a16a..6608ebd 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1559,7 +1559,8 @@ static void get_markers(struct elf_info *info, struct module *mod)
>                        const char *name = strings + sym->st_value;
>                        const char *fmt = strchr(name, '\0') + 1;
>                        char *line = NULL;
> -                       asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
> +                       if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
> +                               fatal("asprintf() with %s failed\n", name);
>                        NOFAIL(line);
>                        mod->markers[n++] = line;
>                }
> @@ -1979,7 +1980,8 @@ static void write_dump(const char *fname)
>  static void add_marker(struct module *mod, const char *name, const char *fmt)
>  {
>        char *line = NULL;
> -       asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
> +       if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
> +               fatal("asprintf() with %s failed\n", name);
>        NOFAIL(line);
>
>        mod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) *

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

* Re: [PATCH v2] modpost: fix asprintf warnings
  2009-12-10  1:16   ` [PATCH v2] " Mike Frysinger
  2009-12-10  6:52     ` Américo Wang
@ 2009-12-10 11:07     ` Rusty Russell
  2009-12-10 11:52       ` Rusty Russell
  1 sibling, 1 reply; 8+ messages in thread
From: Rusty Russell @ 2009-12-10 11:07 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: linux-kernel

On Thu, 10 Dec 2009 11:46:19 am Mike Frysinger wrote:
> On compilers with security warnings enabled by default, we get:
> 
> scripts/mod/modpost.c: In function 'get_markers':
> scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
>                                      declared with attribute warn_unused_result
> scripts/mod/modpost.c: In function 'add_marker':
> scripts/mod/modpost.c:1982: warning: ignoring return value of 'asprintf',
>                                      declared with attribute warn_unused_result

Actually I think these warnings only occur with -DFORTIFY_SOURCE.  This is
turned on by Ubuntu at least.

I think they're a bad idea (if you really don't care, suppressing them is
really painful), but that's a separate battle...

Applied,
Rusty.

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

* Re: [PATCH v2] modpost: fix asprintf warnings
  2009-12-10 11:07     ` Rusty Russell
@ 2009-12-10 11:52       ` Rusty Russell
  2009-12-10 11:55         ` Mike Frysinger
  0 siblings, 1 reply; 8+ messages in thread
From: Rusty Russell @ 2009-12-10 11:52 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: linux-kernel

On Thu, 10 Dec 2009 09:37:52 pm Rusty Russell wrote:
> On Thu, 10 Dec 2009 11:46:19 am Mike Frysinger wrote:
> > On compilers with security warnings enabled by default, we get:
> > 
> > scripts/mod/modpost.c: In function 'get_markers':
> > scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
...
> Applied,
> Rusty.

Actually, not applied since another patch in my queue deletes that obsolete
code altogether.

Thanks,
Rusty.

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

* Re: [PATCH v2] modpost: fix asprintf warnings
  2009-12-10 11:52       ` Rusty Russell
@ 2009-12-10 11:55         ` Mike Frysinger
  0 siblings, 0 replies; 8+ messages in thread
From: Mike Frysinger @ 2009-12-10 11:55 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel

On Thu, Dec 10, 2009 at 06:52, Rusty Russell wrote:
> On Thu, 10 Dec 2009 09:37:52 pm Rusty Russell wrote:
>> On Thu, 10 Dec 2009 11:46:19 am Mike Frysinger wrote:
>> > On compilers with security warnings enabled by default, we get:
>> >
>> > scripts/mod/modpost.c: In function 'get_markers':
>> > scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
> ...
>> Applied,
>> Rusty.
>
> Actually, not applied since another patch in my queue deletes that obsolete
> code altogether.

WFM.  hopefully new code doesnt trigger warnings too, but i guess i'll
post another patch if it does ;).
-mike

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

end of thread, other threads:[~2009-12-10 11:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-09 12:02 [PATCH] modpost: fix asprintf warnings Mike Frysinger
2009-12-09 15:59 ` Américo Wang
2009-12-09 20:31   ` Mike Frysinger
2009-12-10  1:16   ` [PATCH v2] " Mike Frysinger
2009-12-10  6:52     ` Américo Wang
2009-12-10 11:07     ` Rusty Russell
2009-12-10 11:52       ` Rusty Russell
2009-12-10 11:55         ` Mike Frysinger

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.