[rtems-libbsd commit] mDNS: AnonInfoAnswersQuestion: Fix stack usage

Sebastian Huber sebh at rtems.org
Thu Jan 30 15:35:15 UTC 2014


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Jan 23 14:59:37 2014 +0100

mDNS: AnonInfoAnswersQuestion: Fix stack usage

The mDNSexport is normally defined to be empty, thus mDNSStorage is a
huge stack variable (roughly 50KiB) with random data.

Asuming a global mDNSStorage variable in the mDNSCore makes no sense.

---

 mDNSResponder/mDNSCore/anonymous.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/mDNSResponder/mDNSCore/anonymous.c b/mDNSResponder/mDNSCore/anonymous.c
index 94b102e..55a8317 100644
--- a/mDNSResponder/mDNSCore/anonymous.c
+++ b/mDNSResponder/mDNSCore/anonymous.c
@@ -249,12 +249,17 @@ mDNSexport void SetAnonData(DNSQuestion *q, ResourceRecord *rr, mDNSBool ForQues
     }
 }
 
+mDNSlocal char *RRDisplayStringBuf(const ResourceRecord *const rr, char *const buffer)
+{
+    return GetRRDisplayString_rdb(rr, &rr->rdata->u, buffer);
+}
+
 // returns -1 if the caller should ignore the result
 // returns 1 if the record answers the question
 // returns 0 if the record does not answer the question
 mDNSexport int AnonInfoAnswersQuestion(const ResourceRecord *const rr, const DNSQuestion *const q)
 {
-    mDNSexport mDNS mDNSStorage;
+    char MsgBuffer[MaxMsg];             // Temp storage used while building error log messages
     ResourceRecord *nsec3RR;
     int i;
     AnonymousInfo *qai, *rai;
@@ -337,7 +342,7 @@ mDNSexport int AnonInfoAnswersQuestion(const ResourceRecord *const rr, const DNS
             mDNSPlatformMemCmp(qai->AnonData, rai->AnonData, qai->AnonDataLen) != 0)
         {
             debugf("AnonInfoAnswersQuestion: AnonData mis-match for record  %s question %##s ",
-                RRDisplayString(&mDNSStorage, rr), q->qname.c);
+                RRDisplayStringBuf(rr, MsgBuffer), q->qname.c);
             return 0;
         }
         // AnonData matches i.e they belong to the same group and the same service.
@@ -375,10 +380,10 @@ mDNSexport int AnonInfoAnswersQuestion(const ResourceRecord *const rr, const DNS
         // AnonData can be NULL for the cache entry and if we are hearing our own question back, AnonData is NULL for
         // that too and we can end up here for that case.
         debugf("AnonInfoAnswersQuestion: AnonData %p or nsec3RR %p, NULL for question %##s, record %s", AnonData, nsec3RR,
-            q->qname.c, RRDisplayString(&mDNSStorage, rr));
+            q->qname.c, RRDisplayStringBuf(rr, MsgBuffer));
         return 0;
     }
-    debugf("AnonInfoAnswersQuestion: Validating question %##s, ResourceRecord %s", q->qname.c, RRDisplayString(&mDNSStorage, nsec3RR));
+    debugf("AnonInfoAnswersQuestion: Validating question %##s, ResourceRecord %s", q->qname.c, RRDisplayStringBuf(nsec3RR, MsgBuffer));
 
 
     nsec3 = (rdataNSEC3 *)nsec3RR->rdata->u.data;
@@ -410,7 +415,7 @@ mDNSexport int AnonInfoAnswersQuestion(const ResourceRecord *const rr, const DNS
             return 0;
         }
     }
-    LogInfo("AnonInfoAnswersQuestion: ResourceRecord %s matched question %##s (%s)", RRDisplayString(&mDNSStorage, nsec3RR), q->qname.c, DNSTypeName(q->qtype));
+    LogInfo("AnonInfoAnswersQuestion: ResourceRecord %s matched question %##s (%s)", RRDisplayStringBuf(nsec3RR, MsgBuffer), q->qname.c, DNSTypeName(q->qtype));
     return 1;
 }
 




More information about the vc mailing list