linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] scripts: modpost: check memory allocation results
@ 2018-08-15 19:30 Randy Dunlap
  2018-08-16  2:37 ` Masahiro Yamada
  0 siblings, 1 reply; 2+ messages in thread
From: Randy Dunlap @ 2018-08-15 19:30 UTC (permalink / raw)
  To: linux-kbuild, LKML, Masahiro Yamada; +Cc: Yuexing Wang

From: Randy Dunlap <rdunlap@infradead.org>

Fix missing error check for memory allocation functions in
scripts/mod/modpost.c.

Fixes kernel bugzilla #200319:
https://bugzilla.kernel.org/show_bug.cgi?id=200319

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Yuexing Wang <wangyxlandq@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
---
v2: add checks in more places

 scripts/mod/modpost.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- linux-next-20180814.orig/scripts/mod/modpost.c
+++ linux-next-20180814/scripts/mod/modpost.c
@@ -672,7 +672,7 @@ static void handle_modversions(struct mo
 			if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
 				break;
 			if (symname[0] == '.') {
-				char *munged = strdup(symname);
+				char *munged = NOFAIL(strdup(symname));
 				munged[0] = '_';
 				munged[1] = toupper(munged[1]);
 				symname = munged;
@@ -1318,7 +1318,7 @@ static Elf_Sym *find_elf_symbol2(struct
 static char *sec2annotation(const char *s)
 {
 	if (match(s, init_exit_sections)) {
-		char *p = malloc(20);
+		char *p = NOFAIL(malloc(20));
 		char *r = p;
 
 		*p++ = '_';
@@ -1338,7 +1338,7 @@ static char *sec2annotation(const char *
 			strcat(p, " ");
 		return r;
 	} else {
-		return strdup("");
+		return NOFAIL(strdup(""));
 	}
 }
 
@@ -2036,7 +2036,7 @@ void buf_write(struct buffer *buf, const
 {
 	if (buf->size - buf->pos < len) {
 		buf->size += len + SZ;
-		buf->p = realloc(buf->p, buf->size);
+		buf->p = NOFAIL(realloc(buf->p, buf->size));
 	}
 	strncpy(buf->p + buf->pos, s, len);
 	buf->pos += len;



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

* Re: [PATCH v2] scripts: modpost: check memory allocation results
  2018-08-15 19:30 [PATCH v2] scripts: modpost: check memory allocation results Randy Dunlap
@ 2018-08-16  2:37 ` Masahiro Yamada
  0 siblings, 0 replies; 2+ messages in thread
From: Masahiro Yamada @ 2018-08-16  2:37 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: linux-kbuild, LKML, Yuexing Wang

2018-08-16 4:30 GMT+09:00 Randy Dunlap <rdunlap@infradead.org>:
> From: Randy Dunlap <rdunlap@infradead.org>
>
> Fix missing error check for memory allocation functions in
> scripts/mod/modpost.c.
>
> Fixes kernel bugzilla #200319:
> https://bugzilla.kernel.org/show_bug.cgi?id=200319
>
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Yuexing Wang <wangyxlandq@gmail.com>
> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
> v2: add checks in more places

Applied to linux-kbuild. Thanks!


>  scripts/mod/modpost.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> --- linux-next-20180814.orig/scripts/mod/modpost.c
> +++ linux-next-20180814/scripts/mod/modpost.c
> @@ -672,7 +672,7 @@ static void handle_modversions(struct mo
>                         if (ELF_ST_TYPE(sym->st_info) == STT_SPARC_REGISTER)
>                                 break;
>                         if (symname[0] == '.') {
> -                               char *munged = strdup(symname);
> +                               char *munged = NOFAIL(strdup(symname));
>                                 munged[0] = '_';
>                                 munged[1] = toupper(munged[1]);
>                                 symname = munged;
> @@ -1318,7 +1318,7 @@ static Elf_Sym *find_elf_symbol2(struct
>  static char *sec2annotation(const char *s)
>  {
>         if (match(s, init_exit_sections)) {
> -               char *p = malloc(20);
> +               char *p = NOFAIL(malloc(20));
>                 char *r = p;
>
>                 *p++ = '_';
> @@ -1338,7 +1338,7 @@ static char *sec2annotation(const char *
>                         strcat(p, " ");
>                 return r;
>         } else {
> -               return strdup("");
> +               return NOFAIL(strdup(""));
>         }
>  }
>
> @@ -2036,7 +2036,7 @@ void buf_write(struct buffer *buf, const
>  {
>         if (buf->size - buf->pos < len) {
>                 buf->size += len + SZ;
> -               buf->p = realloc(buf->p, buf->size);
> +               buf->p = NOFAIL(realloc(buf->p, buf->size));
>         }
>         strncpy(buf->p + buf->pos, s, len);
>         buf->pos += len;
>
>



-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2018-08-16  2:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 19:30 [PATCH v2] scripts: modpost: check memory allocation results Randy Dunlap
2018-08-16  2:37 ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).