| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | typedef int (*dn_expand_proto)(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); | - |
| 11 | static dn_expand_proto local_dn_expand = 0; | - |
| 12 | typedef void (*res_nclose_proto)(res_state); | - |
| 13 | static res_nclose_proto local_res_nclose = 0; | - |
| 14 | typedef int (*res_ninit_proto)(res_state); | - |
| 15 | static res_ninit_proto local_res_ninit = 0; | - |
| 16 | typedef int (*res_nquery_proto)(res_state, const char *, int, int, unsigned char *, int); | - |
| 17 | static res_nquery_proto local_res_nquery = 0; | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | struct 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 | | - |
| 29 | static void resolveLibrary() | - |
| 30 | { | - |
| 31 | QLibrary lib(QLatin1String("resolv")); | - |
| 32 | if (!lib.load()) partially evaluated: !lib.load()| no Evaluation Count:0 | yes Evaluation Count:2 |
| 0-2 |
| 33 | return; | 0 |
| 34 | | - |
| 35 | local_dn_expand = dn_expand_proto(lib.resolve("__dn_expand")); | - |
| 36 | if (!local_dn_expand) partially evaluated: !local_dn_expand| 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| 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| 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| 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| 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| 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| 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 | | - |
| 58 | void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply) | - |
| 59 | { | - |
| 60 | | - |
| 61 | static QBasicAtomicInt triedResolve = { (false) }; | - |
| 62 | if (!triedResolve.loadAcquire()) { evaluated: !triedResolve.loadAcquire()| 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()| 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| no Evaluation Count:0 | yes Evaluation Count:41 |
partially evaluated: !local_res_nclose| no Evaluation Count:0 | yes Evaluation Count:41 |
partially evaluated: !local_res_ninit| no Evaluation Count:0 | yes Evaluation Count:41 |
partially evaluated: !local_res_nquery| 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; | 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| no Evaluation Count:0 | yes Evaluation Count:41 |
| 0-41 |
| 81 | reply->error = QDnsLookup::ResolverError; | - |
| 82 | reply->errorString = tr("Resolver initialization failed"); | - |
| 83 | 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)| 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; | 0 |
| 105 | case ns_r_servfail: | - |
| 106 | reply->error = QDnsLookup::ServerFailureError; | - |
| 107 | reply->errorString = tr("Server failure"); | - |
| 108 | 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; | 0 |
| 117 | default: | - |
| 118 | reply->error = QDnsLookup::InvalidReplyError; | - |
| 119 | reply->errorString = tr("Invalid reply received"); | - |
| 120 | return; | 0 |
| 121 | } | - |
| 122 | | - |
| 123 | | - |
| 124 | if (responseLength < int(sizeof(HEADER))) { partially evaluated: responseLength < int(sizeof(HEADER))| no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
| 125 | reply->error = QDnsLookup::InvalidReplyError; | - |
| 126 | reply->errorString = tr("Invalid reply received"); | - |
| 127 | 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| 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; | 0 |
| 138 | } | - |
| 139 | p += status + 4; | - |
| 140 | | - |
| 141 | | - |
| 142 | int answerIndex = 0; | - |
| 143 | while ((p < response + responseLength) && (answerIndex < answerCount)) { evaluated: (p < response + responseLength)| yes Evaluation Count:5 | yes Evaluation Count:4 |
partially evaluated: (answerIndex < answerCount)| 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| 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; | 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| 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; | 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) { partially evaluated: type == QDnsLookup::AAAA| 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; | 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) { partially evaluated: type == QDnsLookup::CNAME| 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; | 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) { evaluated: type == QDnsLookup::NS| 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| 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; | 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| 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| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 211 | reply->error = QDnsLookup::InvalidReplyError; | - |
| 212 | reply->errorString = tr("Invalid pointer record"); | - |
| 213 | 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| 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| 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; | 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| 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; | 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) { partially evaluated: type == QDnsLookup::TXT| 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| 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| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 261 | reply->error = QDnsLookup::InvalidReplyError; | - |
| 262 | reply->errorString = tr("Invalid text record"); | - |
| 263 | 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 | | - |
| | |