2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Don't use reference counting in isc_timer unit

The reference counting and isc_timer_attach()/isc_timer_detach()
semantic are actually misleading because it cannot be used under normal
conditions.  The usual conditions under which is timer used uses the
object where timer is used as argument to the "timer" itself.  This
means that when the caller is using `isc_timer_detach()` it needs the
timer to stop and the isc_timer_detach() does that only if this would be
the last reference.  Unfortunately, this also means that if the timer is
attached elsewhere and the timer is fired it will most likely be
use-after-free, because the object used in the timer no longer exists.

Remove the reference counting from the isc_timer unit, remove
isc_timer_attach() function and rename isc_timer_detach() to
isc_timer_destroy() to better reflect how the API needs to be used.

The only caveat is that the already executed event must be destroyed
before the isc_timer_destroy() is called because the timer is no longet
attached to .ev_destroy_arg.
This commit is contained in:
Ondřej Surý
2022-04-02 00:42:20 +02:00
parent 635fbc7f93
commit ae01ec2823
11 changed files with 69 additions and 95 deletions

View File

@@ -76,7 +76,7 @@ nta_detach(isc_mem_t *mctx, dns_nta_t **ntap) {
if (nta->timer != NULL) {
(void)isc_timer_reset(
nta->timer, isc_timertype_inactive, NULL, true);
isc_timer_detach(&nta->timer);
isc_timer_destroy(&nta->timer);
}
if (dns_rdataset_isassociated(&nta->rdataset)) {
dns_rdataset_disassociate(&nta->rdataset);
@@ -294,7 +294,7 @@ settimer(dns_ntatable_t *ntatable, dns_nta_t *nta, uint32_t lifetime) {
result = isc_timer_reset(nta->timer, isc_timertype_ticker, &interval,
false);
if (result != ISC_R_SUCCESS) {
isc_timer_detach(&nta->timer);
isc_timer_destroy(&nta->timer);
}
return (result);
}
@@ -481,7 +481,7 @@ again:
if (nta->timer != NULL) {
(void)isc_timer_reset(
nta->timer, isc_timertype_inactive, NULL, true);
isc_timer_detach(&nta->timer);
isc_timer_destroy(&nta->timer);
}
result = deletenode(ntatable, foundname);