2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 05:28:00 +00:00

fix: dev: Add missing locks when returning addresses

Add missing locks in dns_zone_getxfrsource4 et al.  Addresses CID 468706, 468708, 468741, 468742, 468785, and 468778.

Cleanup dns_zone_setxfrsource4 et al to now return void.

Remove double copies with dns_zone_getprimaryaddr and dns_zone_getsourceaddr.

Closes #4933

Merge branch '4933-add-missing-locks-when-returning-addresses' into 'main'

See merge request isc-projects/bind9!9485
This commit is contained in:
Mark Andrews 2025-03-15 06:04:34 +00:00
commit 06427720f7
4 changed files with 98 additions and 97 deletions

View File

@ -1603,7 +1603,7 @@ xfrin_xmlrender(dns_zone_t *zone, void *arg) {
isc_sockaddr_format(addrp, addr_buf, sizeof(addr_buf));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR addr_buf));
} else if (is_presoa) {
addr = dns_zone_getsourceaddr(zone);
dns_zone_getsourceaddr(zone, &addr);
isc_sockaddr_format(&addr, addr_buf, sizeof(addr_buf));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR addr_buf));
} else {
@ -2660,7 +2660,7 @@ xfrin_jsonrender(dns_zone_t *zone, void *arg) {
json_object_object_add(xfrinobj, "localaddr",
json_object_new_string(addr_buf));
} else if (is_presoa) {
addr = dns_zone_getsourceaddr(zone);
dns_zone_getsourceaddr(zone, &addr);
isc_sockaddr_format(&addr, addr_buf, sizeof(addr_buf));
json_object_object_add(xfrinobj, "localaddr",
json_object_new_string(addr_buf));

View File

@ -1279,22 +1279,22 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = named_config_get(maps, "parental-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
CHECK(dns_zone_setparentalsrc4(zone, cfg_obj_assockaddr(obj)));
dns_zone_setparentalsrc4(zone, cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "parental-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
CHECK(dns_zone_setparentalsrc6(zone, cfg_obj_assockaddr(obj)));
dns_zone_setparentalsrc6(zone, cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "notify-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
CHECK(dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj)));
dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "notify-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
CHECK(dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj)));
dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "notify-to-soa", &obj);
@ -1938,14 +1938,12 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = named_config_get(maps, "transfer-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
CHECK(dns_zone_setxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
dns_zone_setxfrsource4(mayberaw, cfg_obj_assockaddr(obj));
obj = NULL;
result = named_config_get(maps, "transfer-source-v6", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
CHECK(dns_zone_setxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
dns_zone_setxfrsource6(mayberaw, cfg_obj_assockaddr(obj));
obj = NULL;
(void)named_config_get(maps, "try-tcp-refresh", &obj);

View File

@ -818,7 +818,7 @@ dns_zone_setmaxretrytime(dns_zone_t *zone, uint32_t val);
* val > 0.
*/
isc_result_t
void
dns_zone_setxfrsource4(dns_zone_t *zone, const isc_sockaddr_t *xfrsource);
/*%<
* Set the source address to be used in IPv4 zone transfers.
@ -826,22 +826,20 @@ dns_zone_setxfrsource4(dns_zone_t *zone, const isc_sockaddr_t *xfrsource);
* Require:
*\li 'zone' to be a valid zone.
*\li 'xfrsource' to contain the address.
*
* Returns:
*\li #ISC_R_SUCCESS
*/
isc_sockaddr_t *
dns_zone_getxfrsource4(dns_zone_t *zone);
void
dns_zone_getxfrsource4(dns_zone_t *zone, isc_sockaddr_t *xfrsource);
/*%<
* Returns the source address set by a previous dns_zone_setxfrsource4
* call, or the default of inaddr_any, port 0.
*
* Require:
*\li 'zone' to be a valid zone.
*\li 'xfrsource' to not be NULL
*/
isc_result_t
void
dns_zone_setxfrsource6(dns_zone_t *zone, const isc_sockaddr_t *xfrsource);
/*%<
* Set the source address to be used in IPv6 zone transfers.
@ -849,22 +847,20 @@ dns_zone_setxfrsource6(dns_zone_t *zone, const isc_sockaddr_t *xfrsource);
* Require:
*\li 'zone' to be a valid zone.
*\li 'xfrsource' to contain the address.
*
* Returns:
*\li #ISC_R_SUCCESS
*/
isc_sockaddr_t *
dns_zone_getxfrsource6(dns_zone_t *zone);
void
dns_zone_getxfrsource6(dns_zone_t *zone, isc_sockaddr_t *xfrsource);
/*%<
* Returns the source address set by a previous dns_zone_setxfrsource6
* call, or the default of in6addr_any, port 0.
*
* Require:
*\li 'zone' to be a valid zone.
*\li 'xfrsource' to not be NULL
*/
isc_result_t
void
dns_zone_setparentalsrc4(dns_zone_t *zone, const isc_sockaddr_t *parentalsrc);
/*%<
* Set the source address to be used with IPv4 parental DS queries.
@ -872,22 +868,20 @@ dns_zone_setparentalsrc4(dns_zone_t *zone, const isc_sockaddr_t *parentalsrc);
* Require:
*\li 'zone' to be a valid zone.
*\li 'parentalsrc' to contain the address.
*
* Returns:
*\li #ISC_R_SUCCESS
*/
isc_sockaddr_t *
dns_zone_getparentalsrc4(dns_zone_t *zone);
void
dns_zone_getparentalsrc4(dns_zone_t *zone, isc_sockaddr_t *parentalsrc);
/*%<
* Returns the source address set by a previous dns_zone_setparentalsrc4
* call, or the default of inaddr_any, port 0.
*
* Require:
*\li 'zone' to be a valid zone.
*\li 'parentalsrc' to be non NULL.
*/
isc_result_t
void
dns_zone_setparentalsrc6(dns_zone_t *zone, const isc_sockaddr_t *parentalsrc);
/*%<
* Set the source address to be used with IPv6 parental DS queries.
@ -895,22 +889,20 @@ dns_zone_setparentalsrc6(dns_zone_t *zone, const isc_sockaddr_t *parentalsrc);
* Require:
*\li 'zone' to be a valid zone.
*\li 'parentalsrc' to contain the address.
*
* Returns:
*\li #ISC_R_SUCCESS
*/
isc_sockaddr_t *
dns_zone_getparentalsrc6(dns_zone_t *zone);
void
dns_zone_getparentalsrc6(dns_zone_t *zone, isc_sockaddr_t *parentalsrc);
/*%<
* Returns the source address set by a previous dns_zone_setparentalsrc6
* call, or the default of in6addr_any, port 0.
*
* Require:
*\li 'zone' to be a valid zone.
*\li 'parentalsrc' to be non NULL.
*/
isc_result_t
void
dns_zone_setnotifysrc4(dns_zone_t *zone, const isc_sockaddr_t *notifysrc);
/*%<
* Set the source address to be used with IPv4 NOTIFY messages.
@ -918,22 +910,20 @@ dns_zone_setnotifysrc4(dns_zone_t *zone, const isc_sockaddr_t *notifysrc);
* Require:
*\li 'zone' to be a valid zone.
*\li 'notifysrc' to contain the address.
*
* Returns:
*\li #ISC_R_SUCCESS
*/
isc_sockaddr_t *
dns_zone_getnotifysrc4(dns_zone_t *zone);
void
dns_zone_getnotifysrc4(dns_zone_t *zone, isc_sockaddr_t *notifysrc);
/*%<
* Returns the source address set by a previous dns_zone_setnotifysrc4
* call, or the default of inaddr_any, port 0.
*
* Require:
*\li 'zone' to be a valid zone.
*\li 'notifysrc' to be non NULL.
*/
isc_result_t
void
dns_zone_setnotifysrc6(dns_zone_t *zone, const isc_sockaddr_t *notifysrc);
/*%<
* Set the source address to be used with IPv6 NOTIFY messages.
@ -941,19 +931,17 @@ dns_zone_setnotifysrc6(dns_zone_t *zone, const isc_sockaddr_t *notifysrc);
* Require:
*\li 'zone' to be a valid zone.
*\li 'notifysrc' to contain the address.
*
* Returns:
*\li #ISC_R_SUCCESS
*/
isc_sockaddr_t *
dns_zone_getnotifysrc6(dns_zone_t *zone);
void
dns_zone_getnotifysrc6(dns_zone_t *zone, isc_sockaddr_t *notifysrc);
/*%<
* Returns the source address set by a previous dns_zone_setnotifysrc6
* call, or the default of in6addr_any, port 0.
*
* Require:
*\li 'zone' to be a valid zone.
*\li 'notifysrc' to be non NULL.
*/
void
@ -1528,8 +1516,8 @@ dns_zone_getsigresigninginterval(dns_zone_t *zone);
* \li 'zone' to be a valid zone.
*/
isc_sockaddr_t
dns_zone_getsourceaddr(dns_zone_t *zone);
void
dns_zone_getsourceaddr(dns_zone_t *zone, isc_sockaddr_t *sourceaddr);
/*%<
* Get the zone's source address from which it has last contacted the current
* primary server.
@ -1537,17 +1525,18 @@ dns_zone_getsourceaddr(dns_zone_t *zone);
* Requires:
* \li 'zone' to be a valid zone.
* \li 'zone' has a non-empty primaries list.
* \li 'sourceaddr' to be non-NULL.
*/
isc_result_t
dns_zone_getprimaryaddr(dns_zone_t *zone, isc_sockaddr_t *dest);
dns_zone_getprimaryaddr(dns_zone_t *zone, isc_sockaddr_t *primaryaddr);
/*%<
* Get the zone's current primary server into '*dest'.
* Get the zone's current primary server into '*primaryaddr'.
*
* Requires:
* \li 'zone' to be a valid zone.
* \li 'zone' has a non-empty primaries list.
* \li 'dest' != NULL.
* \li 'primaryaddr' to be non-NULL.
*
* Returns:
*\li #ISC_R_SUCCESS if the current primary server was found

View File

@ -5998,106 +5998,123 @@ dns_zone_getkeyopts(dns_zone_t *zone) {
return atomic_load_relaxed(&zone->keyopts);
}
isc_result_t
void
dns_zone_setxfrsource4(dns_zone_t *zone, const isc_sockaddr_t *xfrsource) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(xfrsource != NULL);
LOCK_ZONE(zone);
zone->xfrsource4 = *xfrsource;
UNLOCK_ZONE(zone);
return ISC_R_SUCCESS;
}
isc_sockaddr_t *
dns_zone_getxfrsource4(dns_zone_t *zone) {
void
dns_zone_getxfrsource4(dns_zone_t *zone, isc_sockaddr_t *xfrsource) {
REQUIRE(DNS_ZONE_VALID(zone));
return &zone->xfrsource4;
REQUIRE(xfrsource != NULL);
LOCK_ZONE(zone);
*xfrsource = zone->xfrsource4;
UNLOCK_ZONE(zone);
}
isc_result_t
void
dns_zone_setxfrsource6(dns_zone_t *zone, const isc_sockaddr_t *xfrsource) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(xfrsource != NULL);
LOCK_ZONE(zone);
zone->xfrsource6 = *xfrsource;
UNLOCK_ZONE(zone);
return ISC_R_SUCCESS;
}
isc_sockaddr_t *
dns_zone_getxfrsource6(dns_zone_t *zone) {
void
dns_zone_getxfrsource6(dns_zone_t *zone, isc_sockaddr_t *xfrsource) {
REQUIRE(DNS_ZONE_VALID(zone));
return &zone->xfrsource6;
REQUIRE(xfrsource != NULL);
LOCK_ZONE(zone);
*xfrsource = zone->xfrsource6;
UNLOCK_ZONE(zone);
}
isc_result_t
void
dns_zone_setparentalsrc4(dns_zone_t *zone, const isc_sockaddr_t *parentalsrc) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(parentalsrc != NULL);
LOCK_ZONE(zone);
zone->parentalsrc4 = *parentalsrc;
UNLOCK_ZONE(zone);
return ISC_R_SUCCESS;
}
isc_sockaddr_t *
dns_zone_getparentalsrc4(dns_zone_t *zone) {
void
dns_zone_getparentalsrc4(dns_zone_t *zone, isc_sockaddr_t *parentalsrc) {
REQUIRE(DNS_ZONE_VALID(zone));
return &zone->parentalsrc4;
REQUIRE(parentalsrc != NULL);
LOCK_ZONE(zone);
*parentalsrc = zone->parentalsrc4;
UNLOCK_ZONE(zone);
}
isc_result_t
void
dns_zone_setparentalsrc6(dns_zone_t *zone, const isc_sockaddr_t *parentalsrc) {
REQUIRE(DNS_ZONE_VALID(zone));
LOCK_ZONE(zone);
zone->parentalsrc6 = *parentalsrc;
UNLOCK_ZONE(zone);
return ISC_R_SUCCESS;
}
isc_sockaddr_t *
dns_zone_getparentalsrc6(dns_zone_t *zone) {
void
dns_zone_getparentalsrc6(dns_zone_t *zone, isc_sockaddr_t *parentalsrc) {
REQUIRE(DNS_ZONE_VALID(zone));
return &zone->parentalsrc6;
REQUIRE(parentalsrc != NULL);
LOCK_ZONE(zone);
*parentalsrc = zone->parentalsrc6;
UNLOCK_ZONE(zone);
}
isc_result_t
void
dns_zone_setnotifysrc4(dns_zone_t *zone, const isc_sockaddr_t *notifysrc) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(notifysrc != NULL);
LOCK_ZONE(zone);
zone->notifysrc4 = *notifysrc;
UNLOCK_ZONE(zone);
return ISC_R_SUCCESS;
}
isc_sockaddr_t *
dns_zone_getnotifysrc4(dns_zone_t *zone) {
void
dns_zone_getnotifysrc4(dns_zone_t *zone, isc_sockaddr_t *notifysrc) {
REQUIRE(DNS_ZONE_VALID(zone));
return &zone->notifysrc4;
REQUIRE(notifysrc != NULL);
LOCK_ZONE(zone);
*notifysrc = zone->notifysrc4;
UNLOCK_ZONE(zone);
}
isc_result_t
void
dns_zone_setnotifysrc6(dns_zone_t *zone, const isc_sockaddr_t *notifysrc) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(notifysrc != NULL);
LOCK_ZONE(zone);
zone->notifysrc6 = *notifysrc;
UNLOCK_ZONE(zone);
return ISC_R_SUCCESS;
}
isc_sockaddr_t *
dns_zone_getnotifysrc6(dns_zone_t *zone) {
void
dns_zone_getnotifysrc6(dns_zone_t *zone, isc_sockaddr_t *notifysrc) {
REQUIRE(DNS_ZONE_VALID(zone));
return &zone->notifysrc6;
REQUIRE(notifysrc != NULL);
LOCK_ZONE(zone);
*notifysrc = zone->notifysrc6;
UNLOCK_ZONE(zone);
}
void
@ -18371,31 +18388,28 @@ dns_zone_getsigresigninginterval(dns_zone_t *zone) {
return zone->sigresigninginterval;
}
isc_sockaddr_t
dns_zone_getsourceaddr(dns_zone_t *zone) {
isc_sockaddr_t sourceaddr;
void
dns_zone_getsourceaddr(dns_zone_t *zone, isc_sockaddr_t *sourceaddr) {
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(sourceaddr != NULL);
LOCK_ZONE(zone);
INSIST(dns_remote_count(&zone->primaries) > 0);
sourceaddr = zone->sourceaddr;
*sourceaddr = zone->sourceaddr;
UNLOCK_ZONE(zone);
return sourceaddr;
}
isc_result_t
dns_zone_getprimaryaddr(dns_zone_t *zone, isc_sockaddr_t *dest) {
dns_zone_getprimaryaddr(dns_zone_t *zone, isc_sockaddr_t *primaryaddr) {
isc_result_t result = ISC_R_NOMORE;
REQUIRE(DNS_ZONE_VALID(zone));
REQUIRE(dest != NULL);
REQUIRE(primaryaddr != NULL);
LOCK_ZONE(zone);
INSIST(dns_remote_count(&zone->primaries) > 0);
if (!dns_remote_done(&zone->primaries)) {
*dest = dns_remote_curraddr(&zone->primaries);
*primaryaddr = dns_remote_curraddr(&zone->primaries);
result = ISC_R_SUCCESS;
}
UNLOCK_ZONE(zone);