Skip to contentSkip to conversation

modpost: fix asprintf warnings

PATCH Superseded Mike Frysinger 4 participants 8 messages Dec 9, 2009 – Dec 10, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modpost: fix asprintf warnings

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.

---
 scripts/mod/modpost.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +4 -2
index 801a16a..c4df538 100644
@@ -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) *
Signature · 1 line
1.6.5.5
#1 lore raw
Quoted 21 lines · Mike Frysinger

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.

---
scripts/mod/modpost.c | 6 ++++--

1 files changed, 4 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +0 -0
index 801a16a..c4df538 100644

scripts/mod/modpost.c static void get_markers(struct elf_info *info, struct module *mod) · line 1563

Quoted 6 lines
scripts/mod/modpost.c +2 -1
@@ -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.

Quoted 21 lines
scripts/mod/modpost.c +2 -1
 			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) *
Signature · 7 lines
1.6.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Signature · 1 line
Live like a child, think like the god.
#2 lore raw
Quoted 12 lines · Américo Wang

scripts/mod/modpost.c static void get_markers(struct elf_info *info, struct module *mod) · line 1563

Quoted 9 lines · Mike Frysinger
scripts/mod/modpost.c +2 -1
@@ -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

#3 lore raw

PATCH v2 1/1 modpost: fix asprintf warnings

In reply to Américo Wang

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.

---
v2
- add missing newline pointed out by Américo Wang

 scripts/mod/modpost.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +4 -2
index 801a16a..6608ebd 100644
@@ -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) *
Signature · 1 line
1.6.5.5
Acked-by on v2 1/1
#4 lore raw
Quoted 9 lines · Mike Frysinger

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

Quoted 3 lines

So check the return value and abort on errors.

Quoted 31 lines

---
v2
       - add missing newline pointed out by Américo Wang

 scripts/mod/modpost.c |    6 ++++--

 1 files changed, 4 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +4 -2
index 801a16a..6608ebd 100644
@@ -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) *

#5 lore raw
In reply to Mike Frysinger
Quoted 8 lines · Mike Frysinger

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.

#6 lore raw
Quoted 5 lines · Rusty Russell
Quoted 4 lines · Mike Frysinger

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',

...

Quoted 2 lines

Applied,
Rusty.

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

Thanks,
Rusty.

#7 lore raw
Quoted 4 lines · Rusty Russell
Quoted 3 lines · Rusty Russell
Quoted 2 lines · Mike Frysinger

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

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

scripts/mod/modpost.c: In function 'get_markers':
scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',

...

Quoted 2 lines

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