Skip to content

Commit c774de1

Browse files
committed
[Fix] Regenerate DNS transaction ID before copying packet to TCP buffer
When switching from UDP to TCP (e.g., on truncated response), the code was copying the packet to the TCP output buffer before regenerating the transaction ID to avoid collisions. This resulted in both UDP and TCP packets having the same transaction ID. Fix by moving the ID regeneration and IO channel switch logic before the memcpy to the TCP output buffer, ensuring the TCP packet contains the updated transaction ID.
1 parent 1833877 commit c774de1

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

contrib/librdns/resolver.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,6 @@ rdns_reschedule_req_over_tcp(struct rdns_request *req, struct rdns_server *serv)
484484
return false;
485485
}
486486

487-
oc->write_buf = ((unsigned char *) oc) + sizeof(*oc);
488-
memcpy(oc->write_buf, req->packet, req->pos);
489-
oc->next_write_size = htons(req->pos);
490-
491-
DL_APPEND(ioc->tcp->output_chain, oc);
492-
493-
if (ioc->tcp->async_write == NULL) {
494-
ioc->tcp->async_write = resolver->async->add_write(
495-
resolver->async->data,
496-
ioc->sock, ioc);
497-
}
498-
499-
req->state = RDNS_REQUEST_TCP;
500487
/* Switch IO channel from UDP to TCP */
501488
rdns_request_remove_from_hash(req);
502489
req->io = ioc;
@@ -518,6 +505,20 @@ rdns_reschedule_req_over_tcp(struct rdns_request *req, struct rdns_server *serv)
518505
}
519506
}
520507

508+
oc->write_buf = ((unsigned char *) oc) + sizeof(*oc);
509+
memcpy(oc->write_buf, req->packet, req->pos);
510+
oc->next_write_size = htons(req->pos);
511+
512+
DL_APPEND(ioc->tcp->output_chain, oc);
513+
514+
if (ioc->tcp->async_write == NULL) {
515+
ioc->tcp->async_write = resolver->async->add_write(
516+
resolver->async->data,
517+
ioc->sock, ioc);
518+
}
519+
520+
req->state = RDNS_REQUEST_TCP;
521+
521522
req->async_event = resolver->async->add_timer(resolver->async->data,
522523
req->timeout, req);
523524

0 commit comments

Comments
 (0)