Skip to content

Commit

Permalink
core: dns cache - safety check for out of bounds index
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jul 27, 2017
1 parent 15f226a commit 59234b8
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/core/dns_cache.c
Expand Up @@ -2333,19 +2333,30 @@ inline static struct dns_rr* dns_srv_get_nxt_rr(struct dns_hash_entry* e,
* extra checks */
for (i=0; (i<idx) && (r_sums[i].r_sum<rand_w); i++);
found:
if(i<MAX_SRV_GRP_IDX) {
#ifdef DNS_CACHE_DEBUG
LM_DBG("(%p, %lx, %d, %u): selected %d/%d in grp. %d"
" (rand_w=%d, rr=%p rd=%p p=%d w=%d rsum=%d)\n",
e, (unsigned long)*tried, *no, now, i, idx, n, rand_w, r_sums[i].rr,
(r_sums[i].rr)?r_sums[i].rr->rdata:0,
(r_sums[i].rr&&r_sums[i].rr->rdata)?((struct srv_rdata*)r_sums[i].rr->rdata)->priority:0,
(r_sums[i].rr&&r_sums[i].rr->rdata)?((struct srv_rdata*)r_sums[i].rr->rdata)->weight:0,
r_sums[i].r_sum);
LM_DBG("(%p, %lx, %d, %u): selected %d/%d in grp. %d"
" (rand_w=%d, rr=%p rd=%p p=%d w=%d rsum=%d)\n",
e, (unsigned long)*tried, *no, now, i, idx, n, rand_w,
r_sums[i].rr, (r_sums[i].rr) ? r_sums[i].rr->rdata : 0,
(r_sums[i].rr && r_sums[i].rr->rdata)
? ((struct srv_rdata *)r_sums[i].rr->rdata)->priority
: 0,
(r_sums[i].rr && r_sums[i].rr->rdata)
? ((struct srv_rdata *)r_sums[i].rr->rdata)->weight
: 0,
r_sums[i].r_sum);
#endif
/* i is the winner */
*no=n; /* grp. start */
if(i<8*sizeof(*tried)) srv_mark_tried(tried, i); /* mark it */
return r_sums[i].rr;
/* i is the winner */
*no = n; /* grp. start */
if(i < 8 * sizeof(*tried))
srv_mark_tried(tried, i); /* mark it */
return r_sums[i].rr;
} else {
LM_WARN("index out of bounds\n");
*no=n;
return 0;
}
no_more_rrs:
*no=n;
return 0;
Expand Down

0 comments on commit 59234b8

Please sign in to comment.