kernel/qdnslookup_unix.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10typedef int (*dn_expand_proto)(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); -
11static dn_expand_proto local_dn_expand = 0; -
12typedef void (*res_nclose_proto)(res_state); -
13static res_nclose_proto local_res_nclose = 0; -
14typedef int (*res_ninit_proto)(res_state); -
15static res_ninit_proto local_res_ninit = 0; -
16typedef int (*res_nquery_proto)(res_state, const char *, int, int, unsigned char *, int); -
17static res_nquery_proto local_res_nquery = 0; -
18 -
19 -
20 -
21struct QDnsLookupStateDeleter -
22{ -
23 static inline void cleanup(struct __res_state *pointer) -
24 { -
25 local_res_nclose(pointer); -
26 }
executed: }
Execution Count:41
41
27}; -
28 -
29static void resolveLibrary() -
30{ -
31 QLibrary lib(QLatin1String("resolv")); -
32 if (!lib.load())
partially evaluated: !lib.load()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
33 return;
never executed: return;
0
34 -
35 local_dn_expand = dn_expand_proto(lib.resolve("__dn_expand")); -
36 if (!local_dn_expand)
partially evaluated: !local_dn_expand
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
37 local_dn_expand = dn_expand_proto(lib.resolve("dn_expand"));
never executed: local_dn_expand = dn_expand_proto(lib.resolve("dn_expand"));
0
38 -
39 local_res_nclose = res_nclose_proto(lib.resolve("__res_nclose")); -
40 if (!local_res_nclose)
partially evaluated: !local_res_nclose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
41 local_res_nclose = res_nclose_proto(lib.resolve("res_9_nclose"));
never executed: local_res_nclose = res_nclose_proto(lib.resolve("res_9_nclose"));
0
42 if (!local_res_nclose)
partially evaluated: !local_res_nclose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
43 local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
never executed: local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
0
44 -
45 local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit")); -
46 if (!local_res_ninit)
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
47 local_res_ninit = res_ninit_proto(lib.resolve("res_9_ninit"));
never executed: local_res_ninit = res_ninit_proto(lib.resolve("res_9_ninit"));
0
48 if (!local_res_ninit)
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
49 local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
never executed: local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
0
50 -
51 local_res_nquery = res_nquery_proto(lib.resolve("__res_nquery")); -
52 if (!local_res_nquery)
partially evaluated: !local_res_nquery
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
53 local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery"));
never executed: local_res_nquery = res_nquery_proto(lib.resolve("res_9_nquery"));
0
54 if (!local_res_nquery)
partially evaluated: !local_res_nquery
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
55 local_res_nquery = res_nquery_proto(lib.resolve("res_nquery"));
never executed: local_res_nquery = res_nquery_proto(lib.resolve("res_nquery"));
0
56}
executed: }
Execution Count:2
2
57 -
58void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply) -
59{ -
60 -
61 static QBasicAtomicInt triedResolve = { (false) }; -
62 if (!triedResolve.loadAcquire()) {
evaluated: !triedResolve.loadAcquire()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:39
2-39
63 QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_ninit)); -
64 if (!triedResolve.load()) {
partially evaluated: !triedResolve.load()
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
65 resolveLibrary(); -
66 triedResolve.storeRelease(true); -
67 }
executed: }
Execution Count:2
2
68 }
executed: }
Execution Count:2
2
69 -
70 -
71 if (!local_dn_expand || !local_res_nclose || !local_res_ninit || !local_res_nquery) {
partially evaluated: !local_dn_expand
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41
partially evaluated: !local_res_nclose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41
partially evaluated: !local_res_nquery
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41
0-41
72 reply->error = QDnsLookup::ResolverError; -
73 reply->errorString = tr("Resolver functions not found"); -
74 return;
never executed: return;
0
75 } -
76 -
77 -
78 struct __res_state state; -
79 memset(&state, 0, sizeof(state)); -
80 if (local_res_ninit(&state) < 0) {
partially evaluated: local_res_ninit(&state) < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41
0-41
81 reply->error = QDnsLookup::ResolverError; -
82 reply->errorString = tr("Resolver initialization failed"); -
83 return;
never executed: return;
0
84 } -
85 -
86 -
87 -
88 QScopedPointer<struct __res_state, QDnsLookupStateDeleter> state_ptr(&state); -
89 -
90 -
91 unsigned char response[512]; -
92 memset(response, 0, sizeof(response)); -
93 const int responseLength = local_res_nquery(&state, requestName, ns_c_in, requestType, response, sizeof(response)); -
94 -
95 -
96 HEADER *header = (HEADER*)response; -
97 const int answerCount = (__extension__ ({ register unsigned short int __v, __x = (unsigned short int) (header->ancount); if (__builtin_constant_p (__x)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); __v; }));
never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8)));
executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc");
Execution Count:41
partially evaluated: __builtin_constant_p (__x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41
0-41
98 switch (header->rcode) { -
99 case ns_r_noerror: -
100 break;
executed: break;
Execution Count:4
4
101 case ns_r_formerr: -
102 reply->error = QDnsLookup::InvalidRequestError; -
103 reply->errorString = tr("Server could not process query"); -
104 return;
never executed: return;
0
105 case ns_r_servfail: -
106 reply->error = QDnsLookup::ServerFailureError; -
107 reply->errorString = tr("Server failure"); -
108 return;
never executed: return;
0
109 case ns_r_nxdomain: -
110 reply->error = QDnsLookup::NotFoundError; -
111 reply->errorString = tr("Non existent domain"); -
112 return;
executed: return;
Execution Count:37
37
113 case ns_r_refused: -
114 reply->error = QDnsLookup::ServerRefusedError; -
115 reply->errorString = tr("Server refused to answer"); -
116 return;
never executed: return;
0
117 default: -
118 reply->error = QDnsLookup::InvalidReplyError; -
119 reply->errorString = tr("Invalid reply received"); -
120 return;
never executed: return;
0
121 } -
122 -
123 -
124 if (responseLength < int(sizeof(HEADER))) {
partially evaluated: responseLength < int(sizeof(HEADER))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
125 reply->error = QDnsLookup::InvalidReplyError; -
126 reply->errorString = tr("Invalid reply received"); -
127 return;
never executed: return;
0
128 } -
129 -
130 -
131 char host[512], answer[512]; -
132 unsigned char *p = response + sizeof(HEADER); -
133 int status = local_dn_expand(response, response + responseLength, p, host, sizeof(host)); -
134 if (status < 0) {
partially evaluated: status < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
135 reply->error = QDnsLookup::InvalidReplyError; -
136 reply->errorString = tr("Could not expand domain name"); -
137 return;
never executed: return;
0
138 } -
139 p += status + 4; -
140 -
141 -
142 int answerIndex = 0; -
143 while ((p < response + responseLength) && (answerIndex < answerCount)) {
evaluated: (p < response + responseLength)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:4
partially evaluated: (answerIndex < answerCount)
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-5
144 status = local_dn_expand(response, response + responseLength, p, host, sizeof(host)); -
145 if (status < 0) {
partially evaluated: status < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
146 reply->error = QDnsLookup::InvalidReplyError; -
147 reply->errorString = tr("Could not expand domain name"); -
148 return;
never executed: return;
0
149 } -
150 const QString name = QUrl::fromAce(host); -
151 -
152 p += status; -
153 const quint16 type = (p[0] << 8) | p[1]; -
154 p += 2; -
155 p += 2; -
156 const quint32 ttl = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; -
157 p += 4; -
158 const quint16 size = (p[0] << 8) | p[1]; -
159 p += 2; -
160 -
161 if (type == QDnsLookup::A) {
partially evaluated: type == QDnsLookup::A
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
162 if (size != 4) {
never evaluated: size != 4
0
163 reply->error = QDnsLookup::InvalidReplyError; -
164 reply->errorString = tr("Invalid IPv4 address record"); -
165 return;
never executed: return;
0
166 } -
167 const quint32 addr = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; -
168 QDnsHostAddressRecord record; -
169 record.d->name = name; -
170 record.d->timeToLive = ttl; -
171 record.d->value = QHostAddress(addr); -
172 reply->hostAddressRecords.append(record); -
173 } else if (type == QDnsLookup::AAAA) {
never executed: }
partially evaluated: type == QDnsLookup::AAAA
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
174 if (size != 16) {
never evaluated: size != 16
0
175 reply->error = QDnsLookup::InvalidReplyError; -
176 reply->errorString = tr("Invalid IPv6 address record"); -
177 return;
never executed: return;
0
178 } -
179 QDnsHostAddressRecord record; -
180 record.d->name = name; -
181 record.d->timeToLive = ttl; -
182 record.d->value = QHostAddress(p); -
183 reply->hostAddressRecords.append(record); -
184 } else if (type == QDnsLookup::CNAME) {
never executed: }
partially evaluated: type == QDnsLookup::CNAME
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5
0-5
185 status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer)); -
186 if (status < 0) {
never evaluated: status < 0
0
187 reply->error = QDnsLookup::InvalidReplyError; -
188 reply->errorString = tr("Invalid canonical name record"); -
189 return;
never executed: return;
0
190 } -
191 QDnsDomainNameRecord record; -
192 record.d->name = name; -
193 record.d->timeToLive = ttl; -
194 record.d->value = QUrl::fromAce(answer); -
195 reply->canonicalNameRecords.append(record); -
196 } else if (type == QDnsLookup::NS) {
never executed: }
evaluated: type == QDnsLookup::NS
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:3
0-3
197 status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer)); -
198 if (status < 0) {
partially evaluated: status < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
199 reply->error = QDnsLookup::InvalidReplyError; -
200 reply->errorString = tr("Invalid name server record"); -
201 return;
never executed: return;
0
202 } -
203 QDnsDomainNameRecord record; -
204 record.d->name = name; -
205 record.d->timeToLive = ttl; -
206 record.d->value = QUrl::fromAce(answer); -
207 reply->nameServerRecords.append(record); -
208 } else if (type == QDnsLookup::PTR) {
executed: }
Execution Count:2
evaluated: type == QDnsLookup::PTR
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
209 status = local_dn_expand(response, response + responseLength, p, answer, sizeof(answer)); -
210 if (status < 0) {
partially evaluated: status < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
211 reply->error = QDnsLookup::InvalidReplyError; -
212 reply->errorString = tr("Invalid pointer record"); -
213 return;
never executed: return;
0
214 } -
215 QDnsDomainNameRecord record; -
216 record.d->name = name; -
217 record.d->timeToLive = ttl; -
218 record.d->value = QUrl::fromAce(answer); -
219 reply->pointerRecords.append(record); -
220 } else if (type == QDnsLookup::MX) {
executed: }
Execution Count:1
evaluated: type == QDnsLookup::MX
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
221 const quint16 preference = (p[0] << 8) | p[1]; -
222 status = local_dn_expand(response, response + responseLength, p + 2, answer, sizeof(answer)); -
223 if (status < 0) {
partially evaluated: status < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
224 reply->error = QDnsLookup::InvalidReplyError; -
225 reply->errorString = tr("Invalid mail exchange record"); -
226 return;
never executed: return;
0
227 } -
228 QDnsMailExchangeRecord record; -
229 record.d->exchange = QUrl::fromAce(answer); -
230 record.d->name = name; -
231 record.d->preference = preference; -
232 record.d->timeToLive = ttl; -
233 reply->mailExchangeRecords.append(record); -
234 } else if (type == QDnsLookup::SRV) {
executed: }
Execution Count:1
partially evaluated: type == QDnsLookup::SRV
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
235 const quint16 priority = (p[0] << 8) | p[1]; -
236 const quint16 weight = (p[2] << 8) | p[3]; -
237 const quint16 port = (p[4] << 8) | p[5]; -
238 status = local_dn_expand(response, response + responseLength, p + 6, answer, sizeof(answer)); -
239 if (status < 0) {
never evaluated: status < 0
0
240 reply->error = QDnsLookup::InvalidReplyError; -
241 reply->errorString = tr("Invalid service record"); -
242 return;
never executed: return;
0
243 } -
244 QDnsServiceRecord record; -
245 record.d->name = name; -
246 record.d->target = QUrl::fromAce(answer); -
247 record.d->port = port; -
248 record.d->priority = priority; -
249 record.d->timeToLive = ttl; -
250 record.d->weight = weight; -
251 reply->serviceRecords.append(record); -
252 } else if (type == QDnsLookup::TXT) {
never executed: }
partially evaluated: type == QDnsLookup::TXT
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
253 unsigned char *txt = p; -
254 QDnsTextRecord record; -
255 record.d->name = name; -
256 record.d->timeToLive = ttl; -
257 while (txt < p + size) {
evaluated: txt < p + size
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
258 const unsigned char length = *txt; -
259 txt++; -
260 if (txt + length > p + size) {
partially evaluated: txt + length > p + size
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
261 reply->error = QDnsLookup::InvalidReplyError; -
262 reply->errorString = tr("Invalid text record"); -
263 return;
never executed: return;
0
264 } -
265 record.d->values << QByteArray((char*)txt, length); -
266 txt += length; -
267 }
executed: }
Execution Count:1
1
268 reply->textRecords.append(record); -
269 }
executed: }
Execution Count:1
1
270 p += size; -
271 answerIndex++; -
272 }
executed: }
Execution Count:5
5
273}
executed: }
Execution Count:4
4
274 -
275 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial