summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/PlatformDomainNameServiceQuery.cpp')
-rw-r--r--Swiften/Network/PlatformDomainNameServiceQuery.cpp57
1 files changed, 32 insertions, 25 deletions
diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
index a5d180b..f884500 100644
--- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp
+++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2016 Isode Limited. 2 * Copyright (c) 2010-2018 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -129,35 +129,42 @@ void PlatformDomainNameServiceQuery::runBlocking() {
129 currentEntry += entryLength; 129 currentEntry += entryLength;
130 currentEntry += NS_RRFIXEDSZ; 130 currentEntry += NS_RRFIXEDSZ;
131 131
132 // Priority 132 try {
133 if (currentEntry + 2 >= messageEnd) { 133 // Priority
134 emitError(); 134 if (currentEntry + 2 >= messageEnd) {
135 return; 135 emitError();
136 } 136 return;
137 record.priority = boost::numeric_cast<int>(ns_get16(currentEntry)); 137 }
138 currentEntry += 2; 138 record.priority = boost::numeric_cast<int>(ns_get16(currentEntry));
139 139 currentEntry += 2;
140 // Weight 140
141 if (currentEntry + 2 >= messageEnd) { 141 // Weight
142 emitError(); 142 if (currentEntry + 2 >= messageEnd) {
143 return; 143 emitError();
144 return;
145 }
146 record.weight = boost::numeric_cast<int>(ns_get16(currentEntry));
147 currentEntry += 2;
148
149 // Port
150 if (currentEntry + 2 >= messageEnd) {
151 emitError();
152 return;
153 }
154 record.port = boost::numeric_cast<unsigned short>(ns_get16(currentEntry));
155 currentEntry += 2;
156
157 // Hostname
158 if (currentEntry >= messageEnd) {
159 emitError();
160 return;
161 }
144 } 162 }
145 record.weight = boost::numeric_cast<int>(ns_get16(currentEntry)); 163 catch (const boost::numeric::bad_numeric_cast&) {
146 currentEntry += 2;
147
148 // Port
149 if (currentEntry + 2 >= messageEnd) {
150 emitError(); 164 emitError();
151 return; 165 return;
152 } 166 }
153 record.port = boost::numeric_cast<int>(ns_get16(currentEntry));
154 currentEntry += 2;
155 167
156 // Hostname
157 if (currentEntry >= messageEnd) {
158 emitError();
159 return;
160 }
161 ByteArray entry; 168 ByteArray entry;
162 entry.resize(NS_MAXDNAME); 169 entry.resize(NS_MAXDNAME);
163 entryLength = dn_expand(messageStart, messageEnd, currentEntry, reinterpret_cast<char*>(vecptr(entry)), entry.size()); 170 entryLength = dn_expand(messageStart, messageEnd, currentEntry, reinterpret_cast<char*>(vecptr(entry)), entry.size());