| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | | - |
| 41 | | - |
| 42 | | - |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | | - |
| 48 | #include "includes.h" | - |
| 49 | | - |
| 50 | #if !defined (HAVE_GETRRSETBYNAME) && !defined (HAVE_LDNS) | - |
| 51 | | - |
| 52 | #include <stdlib.h> | - |
| 53 | #include <string.h> | - |
| 54 | | - |
| 55 | #include <netinet/in.h> | - |
| 56 | #include <arpa/inet.h> | - |
| 57 | | - |
| 58 | #include "getrrsetbyname.h" | - |
| 59 | | - |
| 60 | #if defined(HAVE_DECL_H_ERRNO) && !HAVE_DECL_H_ERRNO | - |
| 61 | extern int h_errno; | - |
| 62 | #endif | - |
| 63 | | - |
| 64 | | - |
| 65 | #ifdef _THREAD_PRIVATE | - |
| 66 | # undef _THREAD_PRIVATE | - |
| 67 | #endif | - |
| 68 | #define _THREAD_PRIVATE(a,b,c) (c) | - |
| 69 | | - |
| 70 | #ifndef HAVE__RES_EXTERN | - |
| 71 | struct __res_state _res; | - |
| 72 | #endif | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | #ifndef INT32SZ | - |
| 84 | # define INT32SZ 4 | - |
| 85 | #endif | - |
| 86 | #ifndef INT16SZ | - |
| 87 | # define INT16SZ 2 | - |
| 88 | #endif | - |
| 89 | | - |
| 90 | #ifndef GETSHORT | - |
| 91 | #define GETSHORT(s, cp) { \ | - |
| 92 | register u_char *t_cp = (u_char *)(cp); \ | - |
| 93 | (s) = ((u_int16_t)t_cp[0] << 8) \ | - |
| 94 | | ((u_int16_t)t_cp[1]) \ | - |
| 95 | ; \ | - |
| 96 | (cp) += INT16SZ; \ | - |
| 97 | } | - |
| 98 | #endif | - |
| 99 | | - |
| 100 | #ifndef GETLONG | - |
| 101 | #define GETLONG(l, cp) { \ | - |
| 102 | register u_char *t_cp = (u_char *)(cp); \ | - |
| 103 | (l) = ((u_int32_t)t_cp[0] << 24) \ | - |
| 104 | | ((u_int32_t)t_cp[1] << 16) \ | - |
| 105 | | ((u_int32_t)t_cp[2] << 8) \ | - |
| 106 | | ((u_int32_t)t_cp[3]) \ | - |
| 107 | ; \ | - |
| 108 | (cp) += INT32SZ; \ | - |
| 109 | } | - |
| 110 | #endif | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | #ifndef HAVE__GETSHORT | - |
| 117 | static u_int16_t | - |
| 118 | _getshort(msgp) | - |
| 119 | register const u_char *msgp; | - |
| 120 | { | - |
| 121 | register u_int16_t u; | - |
| 122 | | - |
| 123 | GETSHORT(u, msgp); | - |
| 124 | return (u); | - |
| 125 | } | - |
| 126 | #elif defined(HAVE_DECL__GETSHORT) && (HAVE_DECL__GETSHORT == 0) | - |
| 127 | u_int16_t _getshort(register const u_char *); | - |
| 128 | #endif | - |
| 129 | | - |
| 130 | #ifndef HAVE__GETLONG | - |
| 131 | static u_int32_t | - |
| 132 | _getlong(msgp) | - |
| 133 | register const u_char *msgp; | - |
| 134 | { | - |
| 135 | register u_int32_t u; | - |
| 136 | | - |
| 137 | GETLONG(u, msgp); | - |
| 138 | return (u); | - |
| 139 | } | - |
| 140 | #elif defined(HAVE_DECL__GETLONG) && (HAVE_DECL__GETLONG == 0) | - |
| 141 | u_int32_t _getlong(register const u_char *); | - |
| 142 | #endif | - |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| 146 | #define ANSWER_BUFFER_SIZE 0xffff | - |
| 147 | | - |
| 148 | struct dns_query { | - |
| 149 | char *name; | - |
| 150 | u_int16_t type; | - |
| 151 | u_int16_t class; | - |
| 152 | struct dns_query *next; | - |
| 153 | }; | - |
| 154 | | - |
| 155 | struct dns_rr { | - |
| 156 | char *name; | - |
| 157 | u_int16_t type; | - |
| 158 | u_int16_t class; | - |
| 159 | u_int16_t ttl; | - |
| 160 | u_int16_t size; | - |
| 161 | void *rdata; | - |
| 162 | struct dns_rr *next; | - |
| 163 | }; | - |
| 164 | | - |
| 165 | struct dns_response { | - |
| 166 | HEADER header; | - |
| 167 | struct dns_query *query; | - |
| 168 | struct dns_rr *answer; | - |
| 169 | struct dns_rr *authority; | - |
| 170 | struct dns_rr *additional; | - |
| 171 | }; | - |
| 172 | | - |
| 173 | static struct dns_response *parse_dns_response(const u_char *, int); | - |
| 174 | static struct dns_query *parse_dns_qsection(const u_char *, int, | - |
| 175 | const u_char **, int); | - |
| 176 | static struct dns_rr *parse_dns_rrsection(const u_char *, int, const u_char **, | - |
| 177 | int); | - |
| 178 | | - |
| 179 | static void free_dns_query(struct dns_query *); | - |
| 180 | static void free_dns_rr(struct dns_rr *); | - |
| 181 | static void free_dns_response(struct dns_response *); | - |
| 182 | | - |
| 183 | static int count_dns_rr(struct dns_rr *, u_int16_t, u_int16_t); | - |
| 184 | | - |
| 185 | int | - |
| 186 | getrrsetbyname(const char *hostname, unsigned int rdclass, | - |
| 187 | unsigned int rdtype, unsigned int flags, | - |
| 188 | struct rrsetinfo **res) | - |
| 189 | { | - |
| 190 | struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); | - |
| 191 | int result; | - |
| 192 | struct rrsetinfo *rrset = NULL; | - |
| 193 | struct dns_response *response = NULL; | - |
| 194 | struct dns_rr *rr; | - |
| 195 | struct rdatainfo *rdata; | - |
| 196 | int length; | - |
| 197 | unsigned int index_ans, index_sig; | - |
| 198 | u_char answer[ANSWER_BUFFER_SIZE]; | - |
| 199 | | - |
| 200 | | - |
| 201 | if (rdclass > 0xffff || rdtype > 0xffff) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 202 | result = ERRSET_INVAL; | - |
| 203 | goto fail; never executed: goto fail; | 0 |
| 204 | } | - |
| 205 | | - |
| 206 | | - |
| 207 | if (rdclass == 0xff || rdtype == 0xff) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 208 | result = ERRSET_INVAL; | - |
| 209 | goto fail; never executed: goto fail; | 0 |
| 210 | } | - |
| 211 | | - |
| 212 | | - |
| 213 | if (flags) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 214 | result = ERRSET_INVAL; | - |
| 215 | goto fail; never executed: goto fail; | 0 |
| 216 | } | - |
| 217 | | - |
| 218 | | - |
| 219 | if ((_resp->options & RES_INIT) == 0 && res_init() == -1) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 220 | result = ERRSET_FAIL; | - |
| 221 | goto fail; never executed: goto fail; | 0 |
| 222 | } | - |
| 223 | | - |
| 224 | #ifdef DEBUG | - |
| 225 | _resp->options |= RES_DEBUG; | - |
| 226 | #endif /* DEBUG */ | - |
| 227 | | - |
| 228 | #ifdef RES_USE_DNSSEC | - |
| 229 | | - |
| 230 | if (_resp->options & RES_USE_EDNS0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 231 | _resp->options |= RES_USE_DNSSEC; never executed: _resp->options |= 0x00800000 ; | 0 |
| 232 | #endif /* RES_USE_DNSEC */ | - |
| 233 | | - |
| 234 | | - |
| 235 | length = res_query(hostname, (signed int) rdclass, (signed int) rdtype, | - |
| 236 | answer, sizeof(answer)); | - |
| 237 | if (length < 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 238 | switch(h_errno) { | - |
| 239 | case HOST_NOT_FOUND: never executed: case 1 : | 0 |
| 240 | result = ERRSET_NONAME; | - |
| 241 | goto fail; never executed: goto fail; | 0 |
| 242 | case NO_DATA: never executed: case 4 : | 0 |
| 243 | result = ERRSET_NODATA; | - |
| 244 | goto fail; never executed: goto fail; | 0 |
| 245 | default: never executed: default: | 0 |
| 246 | result = ERRSET_FAIL; | - |
| 247 | goto fail; never executed: goto fail; | 0 |
| 248 | } | - |
| 249 | } | - |
| 250 | | - |
| 251 | | - |
| 252 | response = parse_dns_response(answer, length); | - |
| 253 | if (response == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 254 | result = ERRSET_FAIL; | - |
| 255 | goto fail; never executed: goto fail; | 0 |
| 256 | } | - |
| 257 | | - |
| 258 | if (response->header.qdcount != 1) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 259 | result = ERRSET_FAIL; | - |
| 260 | goto fail; never executed: goto fail; | 0 |
| 261 | } | - |
| 262 | | - |
| 263 | | - |
| 264 | rrset = calloc(1, sizeof(struct rrsetinfo)); | - |
| 265 | if (rrset == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 266 | result = ERRSET_NOMEMORY; | - |
| 267 | goto fail; never executed: goto fail; | 0 |
| 268 | } | - |
| 269 | rrset->rri_rdclass = response->query->class; | - |
| 270 | rrset->rri_rdtype = response->query->type; | - |
| 271 | rrset->rri_ttl = response->answer->ttl; | - |
| 272 | rrset->rri_nrdatas = response->header.ancount; | - |
| 273 | | - |
| 274 | #ifdef HAVE_HEADER_AD | - |
| 275 | | - |
| 276 | if (response->header.ad == 1)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 277 | rrset->rri_flags |= RRSET_VALIDATED; never executed: rrset->rri_flags |= 1; | 0 |
| 278 | #endif | - |
| 279 | | - |
| 280 | | - |
| 281 | rrset->rri_name = strdup(response->answer->name); never executed: __retval = (char *) memcpy (__retval, response->answer->name , __len); | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 282 | if (rrset->rri_name == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 283 | result = ERRSET_NOMEMORY; | - |
| 284 | goto fail; never executed: goto fail; | 0 |
| 285 | } | - |
| 286 | | - |
| 287 | | - |
| 288 | rrset->rri_nrdatas = count_dns_rr(response->answer, rrset->rri_rdclass, | - |
| 289 | rrset->rri_rdtype); | - |
| 290 | rrset->rri_nsigs = count_dns_rr(response->answer, rrset->rri_rdclass, | - |
| 291 | T_RRSIG); | - |
| 292 | | - |
| 293 | | - |
| 294 | rrset->rri_rdatas = calloc(rrset->rri_nrdatas, | - |
| 295 | sizeof(struct rdatainfo)); | - |
| 296 | if (rrset->rri_rdatas == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 297 | result = ERRSET_NOMEMORY; | - |
| 298 | goto fail; never executed: goto fail; | 0 |
| 299 | } | - |
| 300 | | - |
| 301 | | - |
| 302 | if (rrset->rri_nsigs > 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 303 | rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); | - |
| 304 | if (rrset->rri_sigs == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 305 | result = ERRSET_NOMEMORY; | - |
| 306 | goto fail; never executed: goto fail; | 0 |
| 307 | } | - |
| 308 | } never executed: end of block | 0 |
| 309 | | - |
| 310 | | - |
| 311 | for (rr = response->answer, index_ans = 0, index_sig = 0; | - |
| 312 | rr; rr = rr->next) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 313 | | - |
| 314 | rdata = NULL; | - |
| 315 | | - |
| 316 | if (rr->class == rrset->rri_rdclass &&| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 317 | rr->type == rrset->rri_rdtype)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 318 | rdata = &rrset->rri_rdatas[index_ans++]; never executed: rdata = &rrset->rri_rdatas[index_ans++]; | 0 |
| 319 | | - |
| 320 | if (rr->class == rrset->rri_rdclass &&| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 321 | rr->type == T_RRSIG)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 322 | rdata = &rrset->rri_sigs[index_sig++]; never executed: rdata = &rrset->rri_sigs[index_sig++]; | 0 |
| 323 | | - |
| 324 | if (rdata) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 325 | rdata->rdi_length = rr->size; | - |
| 326 | rdata->rdi_data = malloc(rr->size); | - |
| 327 | | - |
| 328 | if (rdata->rdi_data == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 329 | result = ERRSET_NOMEMORY; | - |
| 330 | goto fail; never executed: goto fail; | 0 |
| 331 | } | - |
| 332 | memcpy(rdata->rdi_data, rr->rdata, rr->size); | - |
| 333 | } never executed: end of block | 0 |
| 334 | } never executed: end of block | 0 |
| 335 | free_dns_response(response); | - |
| 336 | | - |
| 337 | *res = rrset; | - |
| 338 | return (ERRSET_SUCCESS); never executed: return (0); | 0 |
| 339 | | - |
| 340 | fail: | - |
| 341 | if (rrset != NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 342 | freerrset(rrset); never executed: freerrset(rrset); | 0 |
| 343 | if (response != NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 344 | free_dns_response(response); never executed: free_dns_response(response); | 0 |
| 345 | return (result); never executed: return (result); | 0 |
| 346 | } | - |
| 347 | | - |
| 348 | void | - |
| 349 | freerrset(struct rrsetinfo *rrset) | - |
| 350 | { | - |
| 351 | u_int16_t i; | - |
| 352 | | - |
| 353 | if (rrset == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 354 | return; never executed: return; | 0 |
| 355 | | - |
| 356 | if (rrset->rri_rdatas) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 357 | for (i = 0; i < rrset->rri_nrdatas; i++) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 358 | if (rrset->rri_rdatas[i].rdi_data == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 359 | break; never executed: break; | 0 |
| 360 | free(rrset->rri_rdatas[i].rdi_data); | - |
| 361 | } never executed: end of block | 0 |
| 362 | free(rrset->rri_rdatas); | - |
| 363 | } never executed: end of block | 0 |
| 364 | | - |
| 365 | if (rrset->rri_sigs) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 366 | for (i = 0; i < rrset->rri_nsigs; i++) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 367 | if (rrset->rri_sigs[i].rdi_data == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 368 | break; never executed: break; | 0 |
| 369 | free(rrset->rri_sigs[i].rdi_data); | - |
| 370 | } never executed: end of block | 0 |
| 371 | free(rrset->rri_sigs); | - |
| 372 | } never executed: end of block | 0 |
| 373 | | - |
| 374 | if (rrset->rri_name)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 375 | free(rrset->rri_name); never executed: free(rrset->rri_name); | 0 |
| 376 | free(rrset); | - |
| 377 | } never executed: end of block | 0 |
| 378 | | - |
| 379 | | - |
| 380 | | - |
| 381 | | - |
| 382 | static struct dns_response * | - |
| 383 | parse_dns_response(const u_char *answer, int size) | - |
| 384 | { | - |
| 385 | struct dns_response *resp; | - |
| 386 | const u_char *cp; | - |
| 387 | | - |
| 388 | | - |
| 389 | resp = calloc(1, sizeof(*resp)); | - |
| 390 | if (resp == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 391 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 392 | | - |
| 393 | | - |
| 394 | cp = answer; | - |
| 395 | | - |
| 396 | | - |
| 397 | memcpy(&resp->header, cp, HFIXEDSZ); | - |
| 398 | cp += HFIXEDSZ; | - |
| 399 | | - |
| 400 | | - |
| 401 | resp->header.qdcount = ntohs(resp->header.qdcount); never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); never executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 402 | resp->header.ancount = ntohs(resp->header.ancount); never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); never executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 403 | resp->header.nscount = ntohs(resp->header.nscount); never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); never executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 404 | resp->header.arcount = ntohs(resp->header.arcount); never executed: __v = ((unsigned short int) ((((__x) >> 8) & 0xff) | (((__x) & 0xff) << 8))); never executed: __asm__ ("rorw $8, %w0" : "=r" (__v) : "0" (__x) : "cc"); | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 405 | | - |
| 406 | | - |
| 407 | if (resp->header.qdcount < 1) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 408 | free_dns_response(resp); | - |
| 409 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 410 | } | - |
| 411 | | - |
| 412 | | - |
| 413 | resp->query = parse_dns_qsection(answer, size, &cp, | - |
| 414 | resp->header.qdcount); | - |
| 415 | if (resp->header.qdcount && resp->query == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 416 | free_dns_response(resp); | - |
| 417 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 418 | } | - |
| 419 | | - |
| 420 | | - |
| 421 | resp->answer = parse_dns_rrsection(answer, size, &cp, | - |
| 422 | resp->header.ancount); | - |
| 423 | if (resp->header.ancount && resp->answer == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 424 | free_dns_response(resp); | - |
| 425 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 426 | } | - |
| 427 | | - |
| 428 | | - |
| 429 | resp->authority = parse_dns_rrsection(answer, size, &cp, | - |
| 430 | resp->header.nscount); | - |
| 431 | if (resp->header.nscount && resp->authority == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 432 | free_dns_response(resp); | - |
| 433 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 434 | } | - |
| 435 | | - |
| 436 | | - |
| 437 | resp->additional = parse_dns_rrsection(answer, size, &cp, | - |
| 438 | resp->header.arcount); | - |
| 439 | if (resp->header.arcount && resp->additional == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 440 | free_dns_response(resp); | - |
| 441 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 442 | } | - |
| 443 | | - |
| 444 | return (resp); never executed: return (resp); | 0 |
| 445 | } | - |
| 446 | | - |
| 447 | static struct dns_query * | - |
| 448 | parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count) | - |
| 449 | { | - |
| 450 | struct dns_query *head, *curr, *prev; | - |
| 451 | int i, length; | - |
| 452 | char name[MAXDNAME]; | - |
| 453 | | - |
| 454 | for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 455 | | - |
| 456 | | - |
| 457 | curr = calloc(1, sizeof(struct dns_query)); | - |
| 458 | if (curr == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 459 | free_dns_query(head); | - |
| 460 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 461 | } | - |
| 462 | if (head == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 463 | head = curr; never executed: head = curr; | 0 |
| 464 | if (prev != NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 465 | prev->next = curr; never executed: prev->next = curr; | 0 |
| 466 | | - |
| 467 | | - |
| 468 | length = dn_expand(answer, answer + size, *cp, name, | - |
| 469 | sizeof(name)); | - |
| 470 | if (length < 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 471 | free_dns_query(head); | - |
| 472 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 473 | } | - |
| 474 | curr->name = strdup(name); never executed: __retval = (char *) memcpy (__retval, name , __len); | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 475 | if (curr->name == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 476 | free_dns_query(head); | - |
| 477 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 478 | } | - |
| 479 | *cp += length; | - |
| 480 | | - |
| 481 | | - |
| 482 | curr->type = _getshort(*cp); | - |
| 483 | *cp += INT16SZ; | - |
| 484 | | - |
| 485 | | - |
| 486 | curr->class = _getshort(*cp); | - |
| 487 | *cp += INT16SZ; | - |
| 488 | } never executed: end of block | 0 |
| 489 | | - |
| 490 | return (head); never executed: return (head); | 0 |
| 491 | } | - |
| 492 | | - |
| 493 | static struct dns_rr * | - |
| 494 | parse_dns_rrsection(const u_char *answer, int size, const u_char **cp, | - |
| 495 | int count) | - |
| 496 | { | - |
| 497 | struct dns_rr *head, *curr, *prev; | - |
| 498 | int i, length; | - |
| 499 | char name[MAXDNAME]; | - |
| 500 | | - |
| 501 | for (i = 1, head = NULL, prev = NULL; i <= count; i++, prev = curr) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 502 | | - |
| 503 | | - |
| 504 | curr = calloc(1, sizeof(struct dns_rr)); | - |
| 505 | if (curr == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 506 | free_dns_rr(head); | - |
| 507 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 508 | } | - |
| 509 | if (head == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 510 | head = curr; never executed: head = curr; | 0 |
| 511 | if (prev != NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 512 | prev->next = curr; never executed: prev->next = curr; | 0 |
| 513 | | - |
| 514 | | - |
| 515 | length = dn_expand(answer, answer + size, *cp, name, | - |
| 516 | sizeof(name)); | - |
| 517 | if (length < 0) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 518 | free_dns_rr(head); | - |
| 519 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 520 | } | - |
| 521 | curr->name = strdup(name); never executed: __retval = (char *) memcpy (__retval, name , __len); | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 522 | if (curr->name == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 523 | free_dns_rr(head); | - |
| 524 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 525 | } | - |
| 526 | *cp += length; | - |
| 527 | | - |
| 528 | | - |
| 529 | curr->type = _getshort(*cp); | - |
| 530 | *cp += INT16SZ; | - |
| 531 | | - |
| 532 | | - |
| 533 | curr->class = _getshort(*cp); | - |
| 534 | *cp += INT16SZ; | - |
| 535 | | - |
| 536 | | - |
| 537 | curr->ttl = _getlong(*cp); | - |
| 538 | *cp += INT32SZ; | - |
| 539 | | - |
| 540 | | - |
| 541 | curr->size = _getshort(*cp); | - |
| 542 | *cp += INT16SZ; | - |
| 543 | | - |
| 544 | | - |
| 545 | curr->rdata = malloc(curr->size); | - |
| 546 | if (curr->rdata == NULL) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 547 | free_dns_rr(head); | - |
| 548 | return (NULL); never executed: return ( ((void *)0) ); | 0 |
| 549 | } | - |
| 550 | memcpy(curr->rdata, *cp, curr->size); | - |
| 551 | *cp += curr->size; | - |
| 552 | } never executed: end of block | 0 |
| 553 | | - |
| 554 | return (head); never executed: return (head); | 0 |
| 555 | } | - |
| 556 | | - |
| 557 | static void | - |
| 558 | free_dns_query(struct dns_query *p) | - |
| 559 | { | - |
| 560 | if (p == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 561 | return; never executed: return; | 0 |
| 562 | | - |
| 563 | if (p->name)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 564 | free(p->name); never executed: free(p->name); | 0 |
| 565 | free_dns_query(p->next); | - |
| 566 | free(p); | - |
| 567 | } never executed: end of block | 0 |
| 568 | | - |
| 569 | static void | - |
| 570 | free_dns_rr(struct dns_rr *p) | - |
| 571 | { | - |
| 572 | if (p == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 573 | return; never executed: return; | 0 |
| 574 | | - |
| 575 | if (p->name)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 576 | free(p->name); never executed: free(p->name); | 0 |
| 577 | if (p->rdata)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 578 | free(p->rdata); never executed: free(p->rdata); | 0 |
| 579 | free_dns_rr(p->next); | - |
| 580 | free(p); | - |
| 581 | } never executed: end of block | 0 |
| 582 | | - |
| 583 | static void | - |
| 584 | free_dns_response(struct dns_response *p) | - |
| 585 | { | - |
| 586 | if (p == NULL)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 587 | return; never executed: return; | 0 |
| 588 | | - |
| 589 | free_dns_query(p->query); | - |
| 590 | free_dns_rr(p->answer); | - |
| 591 | free_dns_rr(p->authority); | - |
| 592 | free_dns_rr(p->additional); | - |
| 593 | free(p); | - |
| 594 | } never executed: end of block | 0 |
| 595 | | - |
| 596 | static int | - |
| 597 | count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type) | - |
| 598 | { | - |
| 599 | int n = 0; | - |
| 600 | | - |
| 601 | while(p) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 602 | if (p->class == class && p->type == type)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 603 | n++; never executed: n++; | 0 |
| 604 | p = p->next; | - |
| 605 | } never executed: end of block | 0 |
| 606 | | - |
| 607 | return (n); never executed: return (n); | 0 |
| 608 | } | - |
| 609 | | - |
| 610 | #endif /* !defined (HAVE_GETRRSETBYNAME) && !defined (HAVE_LDNS) */ | - |
| | |