[rtems-libbsd commit] mDNS: Avoid uninitialized memory

Sebastian Huber sebh at rtems.org
Tue Nov 4 12:02:23 UTC 2014


Module:    rtems-libbsd
Branch:    master
Commit:    d496d66f63539497153e8e87f7155cf129e01379
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=d496d66f63539497153e8e87f7155cf129e01379

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Nov  4 11:56:59 2014 +0100

mDNS: Avoid uninitialized memory

Use calloc() instead of malloc().

---

 mDNSResponder/mDNSPosix/mDNSPosix.c |    4 ++--
 mDNSResponder/mDNSPosix/mDNSUNP.c   |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mDNSResponder/mDNSPosix/mDNSPosix.c b/mDNSResponder/mDNSPosix/mDNSPosix.c
index 06a8d47..83b8247 100755
--- a/mDNSResponder/mDNSPosix/mDNSPosix.c
+++ b/mDNSResponder/mDNSPosix/mDNSPosix.c
@@ -834,7 +834,7 @@ mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct
     assert(intfMask != NULL);
 
     // Allocate the interface structure itself.
-    intf = (PosixNetworkInterface*)malloc(sizeof(*intf));
+    intf = (PosixNetworkInterface*)calloc(1, sizeof(*intf));
     if (intf == NULL) { assert(0); err = ENOMEM; }
 
     // And make a copy of the intfName.
@@ -1433,7 +1433,7 @@ mDNSexport void    mDNSPlatformMemZero(void *dst, mDNSu32 len)
     memset(dst, 0, len);
 }
 
-mDNSexport void *  mDNSPlatformMemAllocate(mDNSu32 len) { return(malloc(len)); }
+mDNSexport void *  mDNSPlatformMemAllocate(mDNSu32 len) { return(calloc(1, len)); }
 mDNSexport void    mDNSPlatformMemFree    (void *mem)   { free(mem); }
 
 mDNSexport mDNSu32 mDNSPlatformRandomSeed(void)
diff --git a/mDNSResponder/mDNSPosix/mDNSUNP.c b/mDNSResponder/mDNSPosix/mDNSUNP.c
index b392fc7..5c4d9fe 100755
--- a/mDNSResponder/mDNSPosix/mDNSUNP.c
+++ b/mDNSResponder/mDNSPosix/mDNSUNP.c
@@ -245,7 +245,7 @@ struct ifi_info *get_ifi_info(int family, int doaliases)
     lastlen = 0;
     len = 100 * sizeof(struct ifreq);   /* initial buffer size guess */
     for ( ; ; ) {
-        buf = (char*)malloc(len);
+        buf = (char*)calloc(1, len);
         if (buf == NULL) {
             goto gotError;
         }



More information about the vc mailing list