[PATCH] libmount: Check malloc return value before use

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The return value of malloc() should be checked for NULL before
dereferencing it. Also realloc(NULL, size) can be used which does the
same thing as malloc(size).

Signed-off-by: Tobias Klauser <tklauser@xxxxxxxxxx>
---
 shlibs/mount/src/utils.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/shlibs/mount/src/utils.c b/shlibs/mount/src/utils.c
index f487383..29f8190 100644
--- a/shlibs/mount/src/utils.c
+++ b/shlibs/mount/src/utils.c
@@ -271,19 +271,18 @@ int mnt_match_options(const char *optstr, const char *pattern)
 char *mnt_strconcat3(char *s, const char *t, const char *u)
 {
      size_t len = 0;
+     int first_alloc = !s;
 
      len = (s ? strlen(s) : 0) + (t ? strlen(t) : 0) + (u ? strlen(u) : 0);
 
      if (!len)
 	     return NULL;
-     if (!s) {
-	     s = malloc(len + 1);
-	     *s = '\0';
-     } else
-	     s = realloc(s, len + 1);
 
+     s = realloc(s, len + 1);
      if (!s)
 	     return NULL;
+     if (first_alloc)
+	     *s = '\0';
      if (t)
 	     strcat(s, t);
      if (u)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux