Skip to contentSkip to conversation

modpost: add NOFAIL to strndup

PATCH In review Denis Efremov 2 participants 2 messages Aug 27, 2019 – Aug 28, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modpost: add NOFAIL to strndup

Add NOFAIL check for the strndup call, because the function allocates memory and can return NULL. All calls to strdup in modpost are checked with NOFAIL.

---
 scripts/mod/modpost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +2 -2
index f277e116e0eb..0255538528fe 100644
@@ -795,9 +795,9 @@ static int match(const char *sym, const char * const pat[])
 
 		/* "*foo*" */
 		if (*p == '*' && *endp == '*') {
-			char *here, *bare = strndup(p + 1, strlen(p) - 2);
+			char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2));
+			char *here = strstr(sym, bare);
 
-			here = strstr(sym, bare);
 			free(bare);
 			if (here != NULL)
 				return 1;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 7 lines · Denis Efremov

Add NOFAIL check for the strndup call, because the function allocates memory and can return NULL. All calls to strdup in modpost are checked with NOFAIL.

---

Applied to linux-kbuild. Thanks.

Quoted 22 lines
 scripts/mod/modpost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +2 -3
index f277e116e0eb..0255538528fe 100644
@@ -795,9 +795,9 @@ static int match(const char *sym, const char * const pat[])
 
                /* "*foo*" */
                if (*p == '*' && *endp == '*') {
-                       char *here, *bare = strndup(p + 1, strlen(p) - 2);
+                       char *bare = NOFAIL(strndup(p + 1, strlen(p) - 2));
+                       char *here = strstr(sym, bare);
 
-                       here = strstr(sym, bare);
                        free(bare);
                        if (here != NULL)
                                return 1;
--

2.21.0

Signature · 2 lines
Best Regards
Masahiro Yamada